摘要:
题目描述: 方法一:分组异或 class Solution { public int[] singleNumbers(int[] nums) { int sum = 0; int [] res = new int[2]; for(int num:nums){ sum ^= num; } int lo 阅读全文
摘要:
题目描述: 自己的提交: 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 阅读全文
摘要:
题目描述: 自己的提交:O(N) class Solution: def maxScore(self, cardPoints: List[int], k: int) -> int: copy1 = [0] + cardPoints[:] copy2 = [0] + cardPoints[::-1] 阅读全文
摘要:
题目描述: 方法一: 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 阅读全文
摘要:
题目描述: 方法一:动态规划 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 阅读全文
摘要:
题目描述: 提交: class Solution: def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: def helper(num,node,temp): if node.left: helper(num+node.lef 阅读全文
摘要:
题目描述: 方法一:递归 最坏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 阅读全文
摘要:
题目描述: 方法一:归并排序 O(nlogn) class Solution: def reversePairs(self, nums: List[int]) -> int: def mergeSort(l=0, r=len(nums)):#左闭右开区间 if r - l > 1: mid = (l 阅读全文
摘要:
题一: 提交:层序遍历bfs O(N) O(N) class Solution: def levelOrder(self, root: TreeNode) -> List[int]: if not root : return [] queue = [root] res = [] while queu 阅读全文
摘要:
题目描述: 方法:动态规划 完全背包问题 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 阅读全文