2 Leadingme

尚未进行身份认证

干啥啥不行,写bug第一名!

等级
TA的排名 6w+

leetcode-5.27[541. 反转字符串 II、345. 反转字符串中的元音字母、557. 反转字符串中的单词 III](python实现)

题目1题解1class Solution: def reverseStr(self, s: str, k: int) -> str: res='' for i in range(0,len(s),2*k): res+=s[i:i+k][::-1]+s[i+k:i+2*k] return res附上题链接题目2题解2class Solution: def reverseVowels(self,

2020-05-27 12:05:24

leetcode-5.25[190. 颠倒二进制位](python实现)

题目1题解1class Solution: def reverseBits(self, n: int) -> int: ans = 0 i = 32 # 循环移动32次 while i > 0: # 向左移动 ans <<= 1 # 移动后将末尾加n的尾部值 ans += n&1

2020-05-25 11:24:18

leetcode-5.24[*671. 二叉树中第二小的节点、728. 自除数、645. 错误的集合](python实现)

题目1题解1# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: """ 每个节点都是正数,并且每个节点的子节点数量只能为 2 或 0。如果一个节点有两个子节点的话,那么这个节点

2020-05-24 13:46:13

leetcode-5.22[*748. 最短完整词、653. 两数之和 IV - 输入 BST、821. 字符的最短距离](python实现)

题目1题解1class Solution: def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str: s = [w for w in licensePlate.lower() if ord(w)>=97 and ord(w)<=122] words.sort(key=lambda x:len(x)) #按单词长度进行排序 for

2020-05-22 13:36:34

leetcode-5.21[581. 最短无序连续子数组、905. 按奇偶排序数组、922. 按奇偶排序数组 II](python实现)

题目1题解1class Solution: def findUnsortedSubarray(self, nums: List[int]) -> int: l,r = 0, len(nums)-1 while l <= r: Max = max(nums[l:r+1]) Min = min(nums[l:r+1]) if nums[l] == Min:

2020-05-21 11:25:00

leetcode-5.20[1356. 根据数字二进制下 1 的数目排序、977. 有序数组的平方、1221. 分割平衡字符串](python实现)

题目1题解1class Solution: def sortByBits(self, arr: List[int]) -> List[int]: res = [] d = {} for i in arr: n = self.oneCount(i) if n not in d: d[n] =[] d[n].append(i)

2020-05-20 11:58:45

leetcode-5.19[1281. 整数的各位积和之差、811. 子域名访问计数、551. 学生出勤记录 I](python实现)

题目1题解1class Solution: def subtractProductAndSum(self, n: int) -> int: cumsum = 0 cummul = 1 while n: temp = n%10 cumsum += temp cummul *= temp n = n//10 return cummul

2020-05-19 12:26:44

leetcode-5.18[985. 查询后的偶数和、404. 左叶子之和](python实现)

题目1题解1class Solution: def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) -> List[int]: S = sum(item for item in A if item%2==0) sum_even = [] for item in queries: index = item[1]

2020-05-18 11:19:49

leetcode-5.16[1022. 从根到叶的二进制数之和、633. 平方数之和、371. 两整数之和](python实现)

题目1题解1# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: # def sumRootToLeaf(self, root: TreeNode) -> int: # "

2020-05-16 12:52:16

leetcode-5.15[560. 和为K的子数组、1337. 方阵中战斗力最弱的 K 行](python实现)

题目1题解1class Solution: def subarraySum(self, nums: List[int], k: int) -> int: hash={0:1} sum=0 count=0 for i in range(len(nums)): sum+=nums[i] if (sum-k) in hash: count+=hash[

2020-05-15 10:11:02

leetcode-5.14[414. 第三大的数、709. 转换成小写字母、766. 托普利茨矩阵](python实现)

题目1题解1class Solution: def thirdMax(self, nums: List[int]) -> int: # 集合去重 nums = list(set(nums)) if len(nums) <= 2: return max(nums) # 三次选择排序O(3n) -> O(n) for i in range(3): max

2020-05-14 11:38:25

leetcode-5.13[867. 转置矩阵、669. 修剪二叉搜索树、1029. 两地调度](python实现)

题目1题解1class Solution: def transpose(self, A: List[List[int]]) -> List[List[int]]: n = len(A[0]) m = len(A) B = [[None for _ in range(len(A))]for _ in range(len(A[0]))] print(B) for i in range(m):

2020-05-13 12:49:59

leetcode-5.12[263. 丑数、884. 两句话中的不常见单词、929. 独特的电子邮件地址](python实现)

题目1题解1class Solution: def isUgly(self, num: int) -> bool: """ 贪心算法 """ # if num < 1: # return False # while num % 2 == 0: # num /= 2 # while num %

2020-05-12 11:37:32

leetcode-5.11[804. 唯一摩尔斯密码词、1207. 独一无二的出现次数](python实现)

题目1题解1class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: Morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-

2020-05-11 12:16:49

leetcode-5.10[965. 单值二叉树、242. 有效的字母异位词、*236. 二叉树的最近公共祖先](python实现)

题目1题解1# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def isUnivalTree(self, root: TreeNode) -> bool: if ro

2020-05-10 11:28:30

leetcode-5.9[680. 验证回文字符串 II、941. 有效的山脉数组、1037. 有效的回旋镖](python实现)

题目1题解1class Solution: def validPalindrome(self, s: str) -> bool: l, r = 0, len(s) - 1 while l < r: if s[l] != s[r]: case1, case2 = s[l:r], s[l+1:r+1] # 如果原数组去头,去尾的两个数组有一个为回文,则整体为回文

2020-05-09 17:00:44

leetcode-5.8[367. 有效的完全平方数、290. 单词规律、914. 卡牌分组](python实现)

题目1题解1class Solution: def isPerfectSquare(self, num: int) -> bool: """ 二分查找 """ if num < 2: return num # 因为除了1以外的所有有效数的完全平方一定小于等于nu...

2020-05-08 11:36:01

leetcode-5.7[LCP 06. 拿硬币、572. 另一个树的子树、LCP 07. 传递信息](python实现)

题目1题解1class Solution: def minCount(self, coins: List[int]) -> int: """ 贪心算法 """ count = 0 for coin in coins: num, mod = divmod(coin,2) ...

2020-05-07 12:15:53

leetcode-5.6[219. 存在重复元素 II、225. 用队列实现栈、226. 翻转二叉树](python实现)

题目1题解1class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: seen = list() n = len(nums) i = 0 while i < n: if num...

2020-05-06 10:38:07

leetcode-5.5[217. 存在重复元素、205. 同构字符串、204. 计数质数](python实现)

题目1题解1class Solution: def containsDuplicate(self, nums: List[int]) -> bool: seen = set() i = 0 n = len(nums) while i < n: if nums[i] not in se...

2020-05-05 10:42:01

查看更多

勋章 我的勋章
  • 签到达人
    签到达人
    累计签到获取,不积跬步,无以至千里,继续坚持!
  • 新人勋章
    新人勋章
    用户发布第一条blink获赞超过3个即可获得
  • 阅读者勋章Lv2
    阅读者勋章Lv2
    授予在CSDN APP累计阅读博文达到7天的你,是你的坚持与努力,使你超越了昨天的自己。
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
  • 勤写标兵Lv4
    勤写标兵Lv4
    授予每个自然周发布9篇以上(包括9篇)原创IT博文的用户。本勋章将于次周周三上午根据用户上周的博文发布情况由系统自动颁发。
  • 分享学徒
    分享学徒
    成功上传1个资源即可获取