2013年10月15日

Count and Say

摘要: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of inte 阅读全文

posted @ 2013-10-15 14:35 waruzhi 阅读(199) 评论(0) 推荐(0) 编辑

Binary Tree Zigzag Level Order Traversal

摘要: Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:[ [3], ... 阅读全文

posted @ 2013-10-15 14:01 waruzhi 阅读(149) 评论(0) 推荐(0) 编辑

Add Binary

摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".思路:先将原字符串反转,对齐逐位进行相加,再把结果反转 1 string addBinary(string a, string b) { 2 // Note: The Solution object is instantiated only once and is reused by each test case. 3 revers 阅读全文

posted @ 2013-10-15 13:05 waruzhi 阅读(138) 评论(0) 推荐(0) 编辑

Subsets II

摘要: 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,IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]思路在上一题的基础上,因为数组... 阅读全文

posted @ 2013-10-15 10:40 waruzhi 阅读(135) 评论(0) 推荐(0) 编辑

Subsets

摘要: Given a set of distinct integers,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,IfS=[1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]思路递归 1 vector > result; 2... 阅读全文

posted @ 2013-10-15 10:15 waruzhi 阅读(146) 评论(0) 推荐(0) 编辑

导航