上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 18 下一页
摘要: 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 @ 2012-11-15 20:37 chkkch 阅读(1360) 评论(1) 推荐(0) 编辑
摘要: 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], []]DFS每次返回当前解,当解深度大于最大深度时返回。 1 c... 阅读全文
posted @ 2012-11-15 20:24 chkkch 阅读(2060) 评论(0) 推荐(0) 编辑
摘要: Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You are respo 阅读全文
posted @ 2012-11-14 21:38 chkkch 阅读(2169) 评论(1) 推荐(0) 编辑
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in the array.二分搜索来找到转折点,也就是最小数的位置。对二分搜索要稍作修改, 阅读全文
posted @ 2012-11-14 21:23 chkkch 阅读(5833) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(logn).If the target is not found in the array, return[-1, -1].For example,Given[5, 7, 7, 8, 8, 10]and target value 8,return[3, 4].二分找最左端,再二 阅读全文
posted @ 2012-11-14 16:30 chkkch 阅读(3102) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following matrix:[ [1, 3, ... 阅读全文
posted @ 2012-11-14 16:21 chkkch 阅读(1780) 评论(1) 推荐(0) 编辑
摘要: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.用树的遍历来检查。 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 *... 阅读全文
posted @ 2012-11-14 16:12 chkkch 阅读(427) 评论(0) 推荐(0) 编辑
摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321每次取出个位,然后放到新的数里。 1 class Solution { 2 public: 3 int reverse(int x) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int sign = x > 0 ? 1 : -1; 7 ... 阅读全文
posted @ 2012-11-14 16:07 chkkch 阅读(1771) 评论(1) 推荐(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)DFS搜索所有的可能解,同时判断解的合法性。 1 class Solution { 2 private: 3 vector<s 阅读全文
posted @ 2012-11-14 16:00 chkkch 阅读(3112) 评论(1) 推荐(0) 编辑
摘要: Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.Note:Givennwill always be valid.Try to do this in one pass.依然 阅读全文
posted @ 2012-11-14 15:41 chkkch 阅读(8339) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 18 下一页