摘要:
Problem Description:Given an unsorted arraynums, reorder itin-placesuch thatnums[0] = nums[2] = nums[i - 1];Ifiis even, thennums[i] & nums) {4 ... 阅读全文
摘要:
Well, after seeing the similar problems, you may have known how to solve this problem. Yeah, just to construct larger numbers from smaller numbers by ... 阅读全文
摘要:
This post shares a nice explanation, which is implemented here. The code is rewritten below. 1 class Solution { 2 public: 3 string minWindow(strin... 阅读全文
摘要:
This problem is relatively easy. The challenge is how to get a concise code. This post shares a very elegant one which traverses each cell of board on... 阅读全文
摘要:
Just don't be scared by this problem :-) It's also very standard backtracking problem. This post shares a very concise code, which is rewritten below ... 阅读全文
摘要:
Just use binary search to find the first bad version.The code is as follows. 1 // Forward declaration of isBadVersion API. 2 bool isBadVersion(int ver... 阅读全文
摘要:
Problem Description: Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition 阅读全文
摘要:
Problem Description:There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more... 阅读全文
摘要:
This problem is designed specifically to use binary search. In fact, in H-Index, someone has already used this idea (you may refer to this post :-))Th... 阅读全文
摘要:
If you've read the Wikipedia article of H-Index, there is already a neat formula there for computing the h-index, which is written below using the not... 阅读全文
摘要:
This link shares a nice solution with explanation using DP. You will be clear of the algorithm after running it on its suggested example:matrix = [[0,... 阅读全文
摘要:
The basic idea is as follows:Create anew_headthat points toheadand use it to locate the immediate node before them-th (notice that it is1-indexed) nod... 阅读全文
摘要:
This link has a very neat code, which is rewritten below using stacksince thepushandpopoperations of it areO(1)time, while thepop_backandpush_backofve... 阅读全文
摘要:
This problem is not difficult. But it is not easy to have a bug-free code. As you write your codes according to the hints, the most important thing is... 阅读全文
摘要:
Problem Description:Given a non-empty binary search tree and a target value, findkvalues in the BST that are closest to the target.Note:Given target v... 阅读全文