摘要: bug:忘记i>0的判断class Solution {public: void nextPermutation(vector<int> &num) { int i=num.size()-1; while(i>0&&num[i]<=num[i-1]) i--; if(i==0)sort(num.begin(),num.end()); else { int k=num[i-1]; int diff=INT_MAX; int inde... 阅读全文
posted @ 2013-05-28 22:34 代码改变未来 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 用vector代替stackclass Solution {public:vector<string>v1; string simplifyPath(string path) { v1.clear(); string s; string temp; for(int i=0;i<path.size();) { if(path[i]=='/') { int j=i+1; temp=""; ... 阅读全文
posted @ 2013-05-28 21:38 代码改变未来 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 不说了,贴代码class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { if(head==NULL)return NULL; ListNode *p=head; int i=1; for(;i<m;i++) p=p->next; for(int j=m;j<n;j++) { ListNode *q=p; for(int k=j;k<n;k++) ... 阅读全文
posted @ 2013-05-28 20:04 代码改变未来 阅读(974) 评论(0) 推荐(0) 编辑