- 博客(25)
- 收藏
- 关注
原创 78. 子集
78. 子集class Solution(object): def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ res = [] tmp = [] n = len(nums) def dfs(i): if i == n:
2020-10-29 21:38:10
48
原创 75. 颜色分类
75. 颜色分类class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: None Do not return anything, modify nums in-place instead. """ n = len(nums) l, r = 0, n-1 for i in r
2020-10-29 18:41:00
89
原创 74. 搜索二维矩阵
74. 搜索二维矩阵class Solution(object): def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ m = len(matrix) if m == 0: return False
2020-10-29 15:46:40
67
原创 73. 矩阵置零
73. 矩阵置零class Solution(object): def setZeroes(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ m = len(matrix) n = len(matrix[0])
2020-10-28 21:42:38
49
原创 64. 最小路径和
64. 最小路径和class Solution(object): def minPathSum(self, grid): """ :type grid: List[List[int]] :rtype: int """ m = len(grid) n = len(grid[0]) res = [[0] * n for i in range(m)] res[0][0] = g
2020-10-28 21:34:21
42
原创 63. 不同路径 II
63. 不同路径 IIclass Solution(object): def uniquePathsWithObstacles(self, obstacleGrid): """ :type obstacleGrid: List[List[int]] :rtype: int """ m = len(obstacleGrid) n = len(obstacleGrid[0]) res = [
2020-10-28 21:19:31
49
原创 62. 不同路径
62. 不同路径class Solution(object): def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ res =[[1] * m] * n for i in range(1, n): for j in range(1, m):
2020-10-27 20:55:26
48
原创 56. 合并区间
56. 合并区间class Solution(object): def merge(self, intervals): """ :type intervals: List[List[int]] :rtype: List[List[int]] """ intervals.sort(key=lambda x:x[0]) merged = [] for interval in interva
2020-10-26 18:40:37
80
原创 55. 跳跃游戏
55. 跳跃游戏class Solution(object): def canJump(self, nums): """ :type nums: List[int] :rtype: bool """ n = len(nums) if n == 0: return False if n == 1: return True if
2020-10-26 18:15:36
58
原创 48. 旋转图像
48. 旋转图像class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ n = len(matrix) if n == 0:
2020-10-23 22:00:54
66
原创 45. 跳跃游戏 II
45. 跳跃游戏 IIclass Solution(object): def jump(self, nums): """ :type nums: List[int] :rtype: int """ n = len(nums) end, max_position, step = 0, 0, 0 for i in range(n-1): max_position =
2020-10-23 20:07:07
52
原创 42. 接雨水
42. 接雨水思路1class Solution(object): def trap(self, height): """ :type height: List[int] :rtype: int """ n = len(height) if n < 3: return 0 res = 0 max_left = [height[0]]
2020-10-22 21:39:46
66
原创 41. 缺失的第一个正数
41. 缺失的第一个正数class Solution(object): def firstMissingPositive(self, nums): """ :type nums: List[int] :rtype: int """ n = len(nums) for i in range(n): if nums[i] <= 0: nums[i
2020-10-19 21:38:14
58
原创 40. 组合总和 II
40. 组合总和 IIclass Solution(object): def combinationSum2(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ def dfs(candidates, begin, end, path, res,
2020-10-19 21:07:52
48
原创 39. 组合总和
39. 组合总和class Solution(object): def combinationSum(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ def dfs(candidates, begin, end, path, res, tar
2020-10-19 20:50:42
44
原创 34. 在排序数组中查找元素的第一个和最后一个位置
34. 在排序数组中查找元素的第一个和最后一个位置原思路class Solution(object): def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ n = len(nums) if n == 0: re
2020-10-15 21:15:49
67
原创 33. 搜索旋转排序数组
33. 搜索旋转排序数组原想法class Solution(object): def search(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ n = len(nums) for i in range(n): if nums[i] == targ
2020-10-15 20:38:41
92
原创 31. 下一个排列
31. 下一个排列class Solution(object): def nextPermutation(self, nums): """ :type nums: List[int] :rtype: None Do not return anything, modify nums in-place instead. """ def swap(nums, l, r): temp = nums[l]
2020-10-14 21:33:34
103
原创 18. 四数之和
18. 四数之和class Solution(object): def fourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] """ nums.sort() n = len(nums) res = [] for i i
2020-10-13 21:36:22
72
原创 16. 最接近的三数之和
16. 最接近的三数之和class Solution(object): def threeSumClosest(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ n = len(nums) nums.sort() res = nums[0] + nums[1]
2020-10-12 21:50:08
78
原创 15. 三数之和
15. 三数之和class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ if not nums: return [] n = len(nums) if n < 3: return []
2020-10-12 20:57:30
97
原创 11. 盛最多水的容器
11. 盛最多水的容器class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int """ i, j, max_area = 0, len(height)-1, 0 while i < j: if height[i] < height[j]:
2020-10-12 18:49:53
67
1
原创 4. 寻找两个正序数组的中位数
4. 寻找两个正序数组的中位数class Solution(object): def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: float """ m = len(nums1) n = len(nums2) mi
2020-10-12 17:51:31
57
原创 Mac安装gensim遇到的坑
Mac安装gensim遇到的坑折腾了一天终于安成功了,其实几条语句就能完成。brew install gfortransudo pip install --upgrade pipsudo pip install numpy --upgrade --ignore-installedsudo pip install scipy --upgrade --ignore-installedsud...
2018-12-21 11:22:45
2622
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人