摘要:
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. Solution: Re... 阅读全文
摘要:
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia... 阅读全文
摘要:
1 class Solution { 2 public: 3 vector > generateMatrix(int n) { 4 if (n == 0) return vector >(); 5 vector > res(n, vector(n)); 6... 阅读全文
摘要:
1 class Solution { 2 public: 3 vector spiralOrder(vector > &matrix) { 4 vector res; 5 if (matrix.empty() || matrix[0].empty()) re... 阅读全文
摘要:
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. Solution... 阅读全文
摘要:
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have ... 阅读全文
摘要:
Sort a linked list using insertion sort. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *nex... 阅读全文
摘要:
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". Solution: '1'-'0' = 1. 1 class Solution... 阅读全文
摘要:
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the ... 阅读全文
摘要:
Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Note: Recursive solution is trivial, could you do it iteratively? Solution: 1. Iterative way (... 阅读全文