摘要: class Solution {public: int lengthOfLongestSubstring(string s) { int maxlen=0; if(s=="")return 0; vector<int>v(s.size(),1); int i; for(i=1;i<s.size();i++) { for(int j=1;j<=v[i-1];j++) { if(s[i]!=s[i-j]) v[i]++... 阅读全文
posted @ 2013-05-22 21:51 代码改变未来 阅读(148) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int atoi(const char *str) { int total; /* current total */ char sign; /* if '-', then negative, otherwise positive */ while ( isspace(*str) ) ++str; if (*str == '-' || *str == '+') sign = *str++; /* ... 阅读全文
posted @ 2013-05-22 17:01 代码改变未来 阅读(188) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: bool isValid(string s) { stack<char>sc; for(int i=0;i<s.size();i++) { if(s[i]=='('||s[i]=='['||s[i]=='{') sc.push(s[i]); if(s[i]==')') { if(!sc.empty()&&sc.top()=='(')sc.pop(); ... 阅读全文
posted @ 2013-05-22 14:52 代码改变未来 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 判断是否回文class Solution {public: bool isPalindrome(string s) { if(s=="")return true; for(int i=0,j=s.size()-1;i<j;) { while(!isalpha(s[i])&&i<j&&!isdigit(s[i]))i++; while(!isalpha(s[j])&&i<j&&!isdigit(s[j]))j--; if(tolower(s[i])==tolower(s[j]... 阅读全文
posted @ 2013-05-22 14:29 代码改变未来 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 细节很多,不是很容易做对class Solution {public: bool isNumber(const char *s) { bool flag; while(*s==' ') s++; const char *s2=s+strlen(s)-1; while(*s2==' ') { s2--; } if(*s=='+'||*s=='-')s++; const char *s1=s; int point=0; ... 阅读全文
posted @ 2013-05-22 14:06 代码改变未来 阅读(248) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int searchInsert(int A[], int n, int target) { int low=0,high=n-1; int m=0; if(A[0]>target)return 0; while(low<=high) { m=low+(high-low)/2; if(A[m]==target)return m; if(A[m]>target) { ... 阅读全文
posted @ 2013-05-22 00:46 代码改变未来 阅读(171) 评论(0) 推荐(0) 编辑