989. Add to Array-Form of Integer

2019-03-05
阅读 2 分钟
2.1k
For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1].Given the array-form A of a non-negative integer X, return the array-form of the integer X+K.Example 1:

171. Excel Sheet Column Number

2019-03-05
阅读 1 分钟
1.2k
Given a column title as appear in an Excel sheet, return its corresponding column number.For example:

1002. Find Common Characters

2019-03-05
阅读 2 分钟
3.1k
Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final ...

859. Buddy Strings

2019-03-05
阅读 2 分钟
1.1k
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B.

557. Reverse Words in a String III

2019-03-05
阅读 2 分钟
1.6k
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

387. First Unique Character in a String

2019-03-04
阅读 1 分钟
1.4k
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.

279. Perfect Squares

2019-03-04
阅读 2 分钟
1.2k
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

322. Coin Change

2019-03-04
阅读 2 分钟
1.2k
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

318. Maximum Product of Word Lengths

2019-03-04
阅读 2 分钟
1.3k
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0.

313. Super Ugly Number

2019-03-04
阅读 2 分钟
1.5k
Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k.

284. Peeking Iterator

2019-03-01
阅读 2 分钟
1.9k
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be returned by the next call to next().

204. Count Primes

2019-02-28
阅读 1 分钟
1.2k
Count the number of prime numbers less than a non-negative number, n. Example: {代码...} 难度:easy 题目:统计小于非负整数n的所有素数。 思路:参考素数筛选法。 Runtime: 11 ms, faster than 94.69% of Java online submissions for Count Primes.Memory Usage: 35.9 MB, less than 21.43% of Java online subm...

275. H-Index II

2019-02-28
阅读 2 分钟
1.2k
Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.

274. H-Index

2019-02-28
阅读 2 分钟
1.2k
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.

264. Ugly Number II

2019-02-28
阅读 1 分钟
1.4k
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.

241. Different Ways to Add Parentheses

2019-02-28
阅读 2 分钟
2.1k
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.

240. Search a 2D Matrix II

2019-02-27
阅读 2 分钟
1.1k
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in each column are sorted in ascending from top to bottom.Example:

238. Product of Array Except Self

2019-02-27
阅读 2 分钟
1.5k
Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Example:

229. Majority Element II

2019-02-27
阅读 2 分钟
1.7k
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:

236. Lowest Common Ancestor of a Binary Tree

2019-02-27
阅读 2 分钟
1.5k
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

299. Bulls and Cows

2019-02-27
阅读 2 分钟
1.3k
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and posi...

300. Longest Increasing Subsequence

2019-02-26
阅读 2 分钟
1.3k
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:

304. Range Sum Query 2D - Immutable

2019-02-26
阅读 2 分钟
1.5k
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).

109. Convert Sorted List to Binary Search Tree

2019-02-26
阅读 2 分钟
1.9k
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.Example:

230. Kth Smallest Element in a BST

2019-02-25
阅读 2 分钟
1.9k
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Example 1:

228. Summary Ranges

2019-02-23
阅读 2 分钟
1.4k
Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:

995. Minimum Number of K Consecutive Bit Flips

2019-02-23
阅读 2 分钟
2k
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.

133. Clone Graph

2019-02-22
阅读 3 分钟
1.7k
Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph contains a label (int) and a list (List[UndirectedGraphNode]) of its neighbors. There is an edge between the given node and each of the nodes in its neighbors.

106. Construct Binary Tree from Inorder and Postorder Traversal

2019-02-22
阅读 2 分钟
1.4k
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, given

105. Construct Binary Tree from Preorder and Inorder Traversal

2019-02-22
阅读 2 分钟
1.5k
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, given