摘要: Implement strStr()Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.class Solution {public: char *strStr(char *haystack, char *needle) { char *s,*t; int i=0,j=strlen(haystack)-strlen(needle); while(i++<=j) { ... 阅读全文
posted @ 2013-05-11 17:35 代码改变未来 阅读(146) 评论(0) 推荐(0) 编辑
摘要: First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space.关键是O(n)复杂度及常量运行空间。采用交换法。class Solution {public: int firstMissingPositive(int A[]... 阅读全文
posted @ 2013-05-11 15:08 代码改变未来 阅读(175) 评论(0) 推荐(0) 编辑