上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 25 下一页
摘要: Write an efficient algorithm that searches for a value in an m x n matrix. 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, .. 阅读全文
posted @ 2013-07-26 18:57 冰点猎手 阅读(260) 评论(0) 推荐(0)
摘要: Implement atoi to convert a string to an integer.int atoi (const char * str);Convert string to integerParses the C-string str interpreting its content as an integral number, which is returned as a value of type int.The function first discards as many whitespace characters (as in isspace) as necessar 阅读全文
posted @ 2013-07-26 16:34 冰点猎手 阅读(247) 评论(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./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val 阅读全文
posted @ 2013-07-26 13:37 冰点猎手 阅读(171) 评论(0) 推荐(0)
摘要: Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution {public: int reverse(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if(x == 0) return x; int flag = 1; if(x r... 阅读全文
posted @ 2013-07-26 11:23 冰点猎手 阅读(129) 评论(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], []]DFS :clas... 阅读全文
posted @ 2013-07-26 10:43 冰点猎手 阅读(226) 评论(0) 推荐(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,If S = [1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []] DFS 的简单应用 : 求组合class So... 阅读全文
posted @ 2013-07-26 10:17 冰点猎手 阅读(255) 评论(0) 推荐(0)
摘要: Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1]. DFS + 剪枝class Solution {public: void DFS(vector &num, int size,vector temp) { if(size == n){ ... 阅读全文
posted @ 2013-07-25 22:46 冰点猎手 阅读(298) 评论(0) 推荐(0)
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1] 找全排列,DFS的一般应用class Solution {public: void DFS(vector &num, int size,vector temp) { if(size == n){ resul... 阅读全文
posted @ 2013-07-25 20:56 冰点猎手 阅读(284) 评论(0) 推荐(0)
摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.  阅读全文
posted @ 2013-07-25 20:42 冰点猎手 阅读(207) 评论(0) 推荐(0)
摘要: Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 分析: DP 问题Initial state:table[i][i] = true.table[i][i+1] = (s[i]==s[i+1]);State Change:if s[i]==s[j],table[i][j]=table[i+1][.. 阅读全文
posted @ 2013-07-25 11:51 冰点猎手 阅读(179) 评论(0) 推荐(0)
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 25 下一页