摘要:
Range Sum Query 2D - Mutable Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) 阅读全文
摘要:
Given two strings S and T, determine if they are both one edit distance apart. 分析:https://segmentfault.com/a/1190000003906621 虽然我们可以用Edit Distance的解法, 阅读全文
摘要:
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 of a celebrity is tha 阅读全文
摘要:
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek()operation -- it es 阅读全文
摘要:
Given two 1d vectors, implement an iterator to return their elements alternately. For example, given two 1d vectors: By calling next repeatedly until 阅读全文
摘要:
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assum 阅读全文
摘要:
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space 阅读全文
摘要:
Preorder: 因为是preorder traversal, 我们需要先print root,然后左节点,最后右节点,而且root左边子树一定比右边子树先print出来,所以,我们可以先把当前root的右节点压栈,然后把root的左节点压栈,这样每次从栈里取的时候,可以保证左边节点的root先取 阅读全文
摘要:
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified. You shou 阅读全文