
leetcode
逍遥游07
这个作者很懒,什么都没留下…
展开
-
leetcode 第14题 Longest Common Prefix
这题很简单,只需要做一个简单的遍历即可 #include #include #include using namespace std; string longestCommonPrefix(vector& strs) { if(strs.empty()) return ""; string comstr=strs[0]; for(int i=1;i!=strs.原创 2015-07-25 19:11:18 · 480 阅读 · 0 评论 -
leetcode 第21题 两个有序列表的合并
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* me原创 2015-08-11 15:46:34 · 709 阅读 · 0 评论 -
leetcode第五题—最长回文字符串
最长回文字符串(Longest Palindromic Substring ) 1.中心结点法,时间复杂度为O(n^2) 回文字符串都是对称的,有两种对称方式,一是关于字符对称,比如a,aba,cabac,这种回文字符串长度都是奇数;二是关于间隔对称,比如aa,abba,cbaabc,这种回文字符串长度都是偶数,所以要分别检测这两种情况。 中心结点法,就是遍历整个字符串,分别原创 2015-07-23 17:52:53 · 2143 阅读 · 0 评论 -
leetcode第6题—zigZag
LeetCode第六题zigZag的简单解法 这题目是一道简单的找规律的题目 0 10 第1行两个数之间的间隔为 10,10,10 1 9 11 第2行两个数之间的间隔为8,2,8,2 2 8 12 第3行两个数之间的间隔为6,4,6,4 3 7 13 第4行两个数之间的间隔为4,6,4,6 4 6 14 第5行两个数之间的间隔为2,8,2,8 5 15 第6行两个数原创 2015-07-23 19:41:59 · 732 阅读 · 0 评论 -
leetcode第11题
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2015-07-24 15:13:05 · 1146 阅读 · 0 评论 -
leetcode 第15题,三个数的和
这题目和两个数的和求法一样,多了一层遍历,所以复杂度为O(n^2) 重要的地方是防止重复vector的push,所以要检测是否重复 #include #include #include using namespace std; vector> threeSum(vector& nums) { vector> ret; if(nums.empty()) return原创 2015-07-25 20:37:44 · 561 阅读 · 0 评论