摘要:
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) { ... 阅读全文
摘要:
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[]... 阅读全文