摘要: class Solution { public: vector<int> plusOne(vector<int> &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<int> result; int carray_bit = 0; digits[digits.size()-1] += 1; for(int i=digits.size()-1;i>=0;i... 阅读全文
posted @ 2012-10-09 21:31 junfeng_feng 阅读(162) 评论(0) 推荐(0) 编辑
摘要: //需要注意细节class Solution { public: string longestCommonPrefix(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function //sort(strs.begin(),strs.end()); string result(""); if (strs.size()==0) { return r... 阅读全文
posted @ 2012-10-09 21:20 junfeng_feng 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 使用统计学的方法:O(n)分治的方法,比较复杂class Solution { public: int maxSubArray(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int maxendinghere=A[0]; int max = maxendinghere; for(int i=1;i<n;i++) { if (maxendin... 阅读全文
posted @ 2012-10-09 20:53 junfeng_feng 阅读(189) 评论(0) 推荐(0) 编辑
摘要: http://www.leetcode.com/onlinejudgeclass Solution { public: vector<string> anagrams(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function multimap<string,string> map; for(int i=0;i<strs.size();i++) { if(s... 阅读全文
posted @ 2012-10-09 17:12 junfeng_feng 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 直接使用加法/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { // Start typing your C/C++ solution below ... 阅读全文
posted @ 2012-10-09 16:10 junfeng_feng 阅读(155) 评论(0) 推荐(0) 编辑
摘要: LeetCode interview Questions:Add binay1.int之类的数可以使用small2.直接在字符串使用二进制的加法http://www.leetcode.com/onlinejudge 需要FQclass Solution { public: int string_to_int(string str) { int result = 0; int level = 1; for(int i = str.length() - 1; i >=0 ; i--) { if (str[i] == '... 阅读全文
posted @ 2012-10-09 15:52 junfeng_feng 阅读(153) 评论(0) 推荐(0) 编辑