摘要: 题目描述: 方法一:二分 class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: m = len(matrix) if m==0: return False n = len(matri 阅读全文
posted @ 2019-07-12 21:06 oldby 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:O(mn) O(1) class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-place instead. 阅读全文
posted @ 2019-07-12 20:48 oldby 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法: class Solution: def simplifyPath(self, path: str) -> str: stack = [] path = path.split("/") for item in path: if item == "..": if stack : st 阅读全文
posted @ 2019-07-12 20:46 oldby 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交:动态规划 class Solution: def minPathSum(self, grid: List[List[int]]) -> int: m = len(grid) n = len(grid[0]) for i in range(1,m): grid[i][0] = 阅读全文
posted @ 2019-07-12 19:43 oldby 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交: class Solution: def uniquePathsWithObstacles(self, obstacleGrid) : m = len(obstacleGrid) n = len(obstacleGrid[0]) for i in range(m): for 阅读全文
posted @ 2019-07-12 19:25 oldby 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一: class Solution: def uniquePaths(self, m: int, n: int) -> int: return int(math.factorial(m+n-2)/math.factorial(m-1)/math.factorial(n-1)) 方法二 阅读全文
posted @ 2019-07-12 18:05 oldby 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一; # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def rotat 阅读全文
posted @ 2019-07-12 17:34 oldby 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一: class Solution: import math def getPermutation(self, n: int, k: int) -> str: result = '' mod = k-1 if n==1:return '1' n_set = [str(i) for i 阅读全文
posted @ 2019-07-12 17:20 oldby 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:O(nlogn) class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: intervals.sort(key=lambda intervals:intervals[0]) m 阅读全文
posted @ 2019-07-12 16:12 oldby 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:O(logn)递归: class Solution: def myPow(self, x: float, n: int) -> float: if n == 0: return 1 if n < 0: return 1/self.myPow(x,-n) if n&1: retur 阅读全文
posted @ 2019-07-12 16:07 oldby 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一: import collections class Solution: def groupAnagrams(self, strs) : ans = collections.defaultdict(list) for s in strs: ans[tuple(sorted(s))] 阅读全文
posted @ 2019-07-12 12:13 oldby 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:先转置再反转 class Solution: def rotate(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-place instead. """ n 阅读全文
posted @ 2019-07-12 11:03 oldby 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交: class Solution: def addStrings(self, num1: str, num2: str) -> str: if len(num1) < len(num2): num1,num2 = num2,num1 num1 = [_ for _ in num 阅读全文
posted @ 2019-07-12 10:25 oldby 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 恢复内容开始 题目描述: 方法一:O(n2) class Solution: def multiply(self, num1: str, num2: str) -> str: def str2int(s): return ord(s) - ord("0") res = 0 num1,num2 = n 阅读全文
posted @ 2019-07-12 09:56 oldby 阅读(129) 评论(0) 推荐(0) 编辑