上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 47 下一页
摘要: 题目描述: 方法一:分组异或 class Solution { public int[] singleNumbers(int[] nums) { int sum = 0; int [] res = new int[2]; for(int num:nums){ sum ^= num; } int lo 阅读全文
posted @ 2020-04-28 12:43 oldby 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交: class Solution: def maxScore(self, s: str) -> int: d = {"0":0,"1":0} for i in s: d[i] += 1 res = 0 l,r = {"0":0,"1":0},d for v,i in enume 阅读全文
posted @ 2020-04-27 09:58 oldby 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 自己的提交:O(N) class Solution: def maxScore(self, cardPoints: List[int], k: int) -> int: copy1 = [0] + cardPoints[:] copy2 = [0] + cardPoints[::-1] 阅读全文
posted @ 2020-04-27 09:54 oldby 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一: class Solution: def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]: a,s,m=[(0,0)],[nums[0][0]],len(nums) while a: b=[] for i,j 阅读全文
posted @ 2020-04-27 09:49 oldby 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:动态规划 O(n) class Solution: def constrainedSubsetSum(self, nums, k: int): dp = [0]*len(nums) dp[0] = nums[0] arr = [(nums[0],0)] for i in rang 阅读全文
posted @ 2020-04-26 17:55 oldby 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 提交: class Solution: def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: def helper(num,node,temp): if node.left: helper(num+node.lef 阅读全文
posted @ 2020-04-26 09:36 oldby 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:递归 最坏O(N^2) class Solution: def verifyPostorder(self, postorder: List[int]) -> bool: def recur(i,j): if i >= j:return True p = i while posto 阅读全文
posted @ 2020-04-25 23:07 oldby 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:归并排序 O(nlogn) class Solution: def reversePairs(self, nums: List[int]) -> int: def mergeSort(l=0, r=len(nums)):#左闭右开区间 if r - l > 1: mid = (l 阅读全文
posted @ 2020-04-24 14:58 oldby 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 题一: 提交:层序遍历bfs O(N) O(N) class Solution: def levelOrder(self, root: TreeNode) -> List[int]: if not root : return [] queue = [root] res = [] while queu 阅读全文
posted @ 2020-04-23 21:40 oldby 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法:动态规划 完全背包问题 class Solution: def waysToChange(self, n: int) -> int: coins = [1,5,10,25] dp = [0] * (n+1) dp[0] = 1 for coin in coins: for i in 阅读全文
posted @ 2020-04-23 20:25 oldby 阅读(171) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 47 下一页