上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 30 下一页
摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.KMP算法! 1 class Solution { ... 阅读全文
posted @ 2014-04-12 18:19 Eason Liu 阅读(7037) 评论(7) 推荐(0) 编辑
摘要: Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.K可能会大于链表的长度,坑爹! 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListN 阅读全文
posted @ 2014-04-11 17:36 Eason Liu 阅读(152) 评论(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)DFS! 1 class Solution { 2 public: 3 bool isVail(string s) { 4 if ( 阅读全文
posted @ 2014-04-11 17:23 Eason Liu 阅读(222) 评论(0) 推荐(0) 编辑
摘要: You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.For example, given:S:"barfoothefoobarman"L:["foo", " 阅读全文
posted @ 2014-04-11 17:02 Eason Liu 阅读(530) 评论(0) 推荐(0) 编辑
摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs... 阅读全文
posted @ 2014-04-11 01:24 Eason Liu 阅读(508) 评论(0) 推荐(0) 编辑
摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]像这样列举所有结果的只能DFS了。不过为什么我老是忘记写++low跟--high呢,都死 阅读全文
posted @ 2014-04-10 23:52 Eason Liu 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.给定一个矩阵中,只有0和1,求出这个矩阵的一个最大的子矩阵,其中只包含1.例如011011101001110111101111100000其实这个问题可以转化为Largest Rectangle in Histogram,先将上面的矩阵转化为:011011201003110142102532100000然后对每一行求直方图的最大面积。class S 阅读全文
posted @ 2014-04-10 21:47 Eason Liu 阅读(2622) 评论(0) 推荐(0) 编辑
摘要: 题目描述:给定两个正整数a,b(1 2 using namespace std; 3 4 int gcd(int a, int b) { 5 int m = a > b ? a : b; 6 int n = a > b ? b : a; 7 return n == 0 ? a : gcd(n, m % n); 8 } 9 10 int main() {11 int a, b;12 int max;13 int count;14 int i;15 while (cin >> a >> b) {16 count ... 阅读全文
posted @ 2014-04-10 20:38 Eason Liu 阅读(239) 评论(0) 推荐(0) 编辑
摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.no comment. 1 /** 2 * Definition for singly-linked li... 阅读全文
posted @ 2014-04-10 18:01 Eason Liu 阅读(203) 评论(0) 推荐(0) 编辑
摘要: he gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code se 阅读全文
posted @ 2014-04-10 17:32 Eason Liu 阅读(2042) 评论(0) 推荐(0) 编辑
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 30 下一页