leetcode
lUNATICF
Code is my treasure
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode 215.Kth Largest Element in an Array
Leetcode 215. Kth Largest Element in an Array 最naive的做法自然就是all in sort sort(nums.begin(),nums.end()); return nums[nums.size() - k]; time complexity: O(nlogn) 然而我们只需要找到第k个最大的数 这样有太多的浪费的操作了原创 2018-01-04 17:38:07 · 320 阅读 · 0 评论 -
Leetcode 125-Valid Palindrome
Leetcode 125-Valid Palindrome 对撞指针 注意下空字符串。 bool isPalindrome(string s) { int i = 0; int j = s.size() - 1; while (i < j) { while (!isalnum(s[i]))++i; while (!isalnum(s[j原创 2018-01-05 15:55:51 · 330 阅读 · 0 评论 -
Leetcode 11-Container With Most Water
Leetcode 11-Container With Most Water 暴力不可取 首先,自然想到最左边和最右边的wall有着最大的宽度。所以如果不用这个最大的宽度,我们就需要两堵墙有着更大的高度。 设最左边的wall有高度h1 最右边的wall高度h2, 之间宽度为w 则s = w*min(h1,h2) 对于h = min(h1,h2)的wall来说 设再选择any wa原创 2018-01-05 18:31:31 · 340 阅读 · 0 评论 -
Leetcode 2-Add two numbers
Leetcode 2-Add two numbers a slightly simple code. ListNode * addTwoNumbers(ListNode * l1, ListNode * l2) { ListNode dummy(0); ListNode * p = &dummy; int sum = 0; while (l1 || l2)原创 2018-01-15 21:28:13 · 315 阅读 · 1 评论
分享