LeetCode规划LEETCODE PATTERNS从LeetCode学演算法Leetcode笔记Leetcode经典题目程式题
1) reverse string
-
Input: [\"h\",\"e\",\"l\",\"o\"]
-
Output: [\"o\",\"l\",\"e\",\"h\"]
-
使用内部swap:
class Solution(object):
def reverseString(self, s):
\"\"\"
:type s: List[str]
:rtype: None
Do not return anything, modify s in-place instead.
\"\"\"
i = 0
j = len(s)-1
while i < j:
s[i], s[j] = s[j], s[i]
i += 1
j -= 1
return s
2) merge intervals (第一类)
- Example: [1,2], [2,3], [4,5], [5,7] -> [1,2,3], [4,5,7]
3) merge intervals (第二类) - M
暂无评论