CoderJesse  
wangjiexi@CS.PKU

2013年3月1日

摘要: 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 original relative order of the nodes in each of the two partitions.For example,Given 1->4->3->2->5->2 and x = 3,return 1->2->2-> 阅读全文
posted @ 2013-03-01 14:13 CoderJesse 阅读(100) 评论(0) 推荐(0)
 
摘要: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-lea... 阅读全文
posted @ 2013-03-01 14:12 CoderJesse 阅读(230) 评论(0) 推荐(0)
 
摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.归并排序。 1 class Solution { 2 public: 3 void merge(int A[], int m, int B... 阅读全文
posted @ 2013-03-01 14:04 CoderJesse 阅读(116) 评论(0) 推荐(0)
 
摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, given n = 2, return [0,1,3,2]. Its gray c 阅读全文
posted @ 2013-03-01 14:03 CoderJesse 阅读(121) 评论(0) 推荐(0)
 
摘要: A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message "12", it 阅读全文
posted @ 2013-03-01 14:02 CoderJesse 阅读(161) 评论(0) 推荐(0)
 
摘要: Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,If S = [1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]每个元素都有两种选择,... 阅读全文
posted @ 2013-03-01 14:01 CoderJesse 阅读(129) 评论(0) 推荐(0)
 
摘要: Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the following condition:1 <= m <= n <= length of list.注意题目Do it in-place and in 阅读全文
posted @ 2013-03-01 13:58 CoderJesse 阅读(115) 评论(0) 推荐(0)
 
摘要: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)深度优先搜索吧。注意剪枝的简单条件。还有注意ip的规则!class Solution {public: vector<st 阅读全文
posted @ 2013-03-01 13:56 CoderJesse 阅读(266) 评论(0) 推荐(0)
 
摘要: Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].不用解释。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), ... 阅读全文
posted @ 2013-03-01 13:54 CoderJesse 阅读(116) 评论(0) 推荐(0)
 
摘要: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / ... 阅读全文
posted @ 2013-03-01 13:53 CoderJesse 阅读(136) 评论(0) 推荐(0)