摘要:
This post shares a very nice solution using two heaps: a max heap for the smaller half and a min heap for the larger half. The code is rewritten below... 阅读全文
摘要:
Problem Description:You are playing the following Flip Game with your friend: Given a string that contains only these two characters:+and-, you and yo... 阅读全文
摘要:
Problem Description:You are playing the following Flip Game with your friend: Given a string that contains only these two characters:+and-, you and yo... 阅读全文
摘要:
Haha, an interesting problem. Just try to let your opponent start with a number that is an integer multiple of 4.1 class Solution {2 public:3 bool... 阅读全文
摘要:
Problem Description:Given apatternand a stringstr, find ifstrfollows the same pattern.Herefollowmeans a full match, such that there is a bijection bet... 阅读全文
摘要:
This problem can be solved in very neat codes (yeah, you will see Stefan posting many nice solutions).The solution in the above link is so nice that I... 阅读全文
摘要:
A solution using additional spaces to solve a copy of the original board is easy. To get an in-place solution, we need to record the information of st... 阅读全文
摘要:
Problem Description:An abbreviation of a word follows the form . Below are some examples of word abbreviations:a) it --> it (n... 阅读全文
摘要:
There are mainly two solutions to solve this problem.The first one is very clever, using the idea of cycle detection, and runs in O(n) time. You may r... 阅读全文
摘要:
Problem Description:You are given am x n2D grid initialized with these three possible values.-1- A wall or an obstacle.0- A gate.INF- Infinity means a... 阅读全文
摘要:
Problem Description:Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in... 阅读全文
摘要:
An interesting problem about iterators. This post shares a very nice solution, which is rewritten below, with minor simplifications.// Below is the in... 阅读全文
摘要:
This post shares a very nice solution, which is rewritten below. 1 class Solution { 2 public: 3 vector addOperators(string num, int target) { 4 ... 阅读全文
摘要:
The key challenge to this problem is to make the code clean. This post has shared a nice example, which is rewritten below in C++.class Solution {publ... 阅读全文
摘要:
Problem Description:Given two 1d vectors, implement an iterator to return their elements alternately.For example, given two 1d vectors:v1 = [1, 2]v2 =... 阅读全文