02 2021 档案
摘要:原题 给你链表的头节点 head 和一个整数 k 。 交换 链表正数第 k 个节点和倒数第 k 个节点的值后,返回链表的头节点(链表 从 1 开始索引)。 示例 1: 输入:head = [1,2,3,4,5], k = 2输出:[1,4,3,2,5]示例 2: 输入:head = [7,9,6,6
阅读全文
摘要:原题 1 class Solution: 2 def maxScore(self, s: str) -> int: 3 ans,lens = 0,len(s) 4 cnt0 = s.count('0') 5 cnt1 = lens - cnt0 6 cur0 = cur1 = 0 7 for i i
阅读全文
摘要:原题 1 class Solution: 2 def getRow(self, rowIndex: int) -> List[int]: 3 ans = [1] 4 for i in range(rowIndex): 5 # tmp = [1] 6 # for j in range(1,len(an
阅读全文
摘要:原题 解法1、2都是大佬写的,题解链接 1、回溯 1 class Solution: 2 def letterCombinations(self, digits: str) -> List[str]: 3 if not digits: return [] 4 5 phone = {'2':['a',
阅读全文
摘要:原题 1 class Solution: 2 def searchRange(self, nums: List[int], target: int) -> List[int]: 3 ans,lens = [-1,-1],len(nums) 4 left,right,flag = 0,lens - 1
阅读全文
摘要:原题 这题代码写得很烂 思路: 将flowerbed数组分段,记录区间端点是0是1,保证每个区间端点以外都是连续的0序列,最后对区间端点进行分类讨论 如flowerbed数组为[0,1,0,0,0,0,1] 则分段为: 【0,1】【1,0,0,0,0,1】 对应区间去除端点外所含0序列长度num分别
阅读全文
摘要:原题 1 class Solution: 2 def summaryRanges(self, nums: List[int]) -> List[str]: 3 left,right,lens,ans = 0,0,len(nums),[] 4 while left < lens: 5 right =
阅读全文
摘要:原题 以下是我的代码,就是简单的字符串操作,可以ac但背离了题意,我之前没接触过Trie 1 class Trie: 2 3 def __init__(self): 4 """ 5 Initialize your data structure here. 6 """ 7 self.trie = se
阅读全文
摘要:原题 1 class Solution: 2 def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: 3 dic1,dic2 = {},{} 4 def helper(nums,dic): 5 for n in nu
阅读全文
摘要:1 import os 2 import shutil 3 4 path = r'D:\\' #当前路径 5 newpath=r'D:\\BackUp\\MUSIC'#新文件夹路径 6 filenames = os.listdir(path)#获取当前路径下的所有文件或文件夹列表 7 os.rena
阅读全文
摘要:原题 1 # Definition for a binary tree node. 2 # class TreeNode: 3 # def __init__(self, x): 4 # self.val = x 5 # self.left = None 6 # self.right = None 7
阅读全文
摘要:原题 1 class Solution: 2 def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': 3 if p.val < root.val and q.val <
阅读全文

浙公网安备 33010602011771号