0017-letter-combinations-of-a-phone-number.cpp 0018-4sum.cpp 0019-remove-nth-node-from-end-of-list.cpp 0020-valid-parentheses.cpp 0021-merge-two-sorted-lists.cpp 0022-generate-parentheses.cpp 0023-merge-k-sorted-lists.cpp 0024-swap-nodes-in-pairs.cpp 0025-reverse-nodes-in-k-group.cpp 0026...
leetcode 53. Maximum Subarray Given an integer arraynums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Follow...
0039-combination-sum.cpp 0040-combination-sum-ii.cpp 0041-first-missing-positive.cpp 0042-trapping-rain-water.cpp 0043-multiply-strings.cpp 0045-jump-game-ii.cpp 0046-permutations.cpp 0048-rotate-image.cpp 0049-group-anagrams.cpp 0050-powx-n.cpp 0051-n-queens.cpp 0052-n-queens-ii.cpp 0053...
蛮直观,可惜运算时间太长leetcode不给过 Given an integer arraynums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum: 我一开始的思路是把合为正数的子数组存起来,一旦合为负,就从新的正数开始,然而运算速度太拖沓。 class Solution: def maxSub...
The brute force method would be to try every possible pair of price combinations, but this would be O(N^2), pretty bad. Also since this is an interview setting you should probably already know that there is a smarter solution. In this case we will use a greedy algorithm approach. We ...