摘要: 自己写的: class Solution: def detectCapitalUse(self, word: str) -> bool: n=len(word) count=0 for i in word: if self.is_upper(i): count+=1 if count==0: ret 阅读全文
posted @ 2024-05-31 12:58 Junior_bond 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 自己写的: class Solution: # getMinimumDifference 方法接收一个二叉树的根节点 root,并返回树中所有节点值的最小差值 def getMinimumDifference(self, root: Optional[TreeNode]) -> int: # 初始化 阅读全文
posted @ 2024-05-31 12:58 Junior_bond 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 自己写的: class Solution: # getMinimumDifference 方法接收一个二叉树的根节点 root,并返回树中所有节点值的最小差值 def getMinimumDifference(self, root: Optional[TreeNode]) -> int: # 初始化 阅读全文
posted @ 2024-05-31 12:57 Junior_bond 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 自己写的: class Solution: def reverseStr(self, s: str, k: int) -> str: # 初始化两个空列表:s_li用于存储切分后的字符串片段,res用于存储处理后的片段 s_li = [] res = [] # 遍历字符串,步长为2*k,切分成每2* 阅读全文
posted @ 2024-05-31 12:57 Junior_bond 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 自己写的,递归 class Solution: def fib(self, n: int) -> int: # 如果 n 是 0,则返回 0,因为这是 Fibonacci 数列的定义 if n == 0: return 0 # 如果 n 是 1,则返回 1,因为这是 Fibonacci 数列的定义 阅读全文
posted @ 2024-05-23 12:30 Junior_bond 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 自己写的: class Solution: def checkPerfectNumber(self, num: int) -> bool: # 如果数字是1,则直接返回False,因为1不是完美数 if num == 1: return False # 初始化一个空的列表来存储因子 factors 阅读全文
posted @ 2024-05-22 13:04 Junior_bond 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 自己写的: from typing import List class Solution: def findRelativeRanks(self, score: List[int]) -> List[str]: # 获取成绩列表的长度 n = len(score) # 复制原始成绩列表 score_ 阅读全文
posted @ 2024-05-21 13:03 Junior_bond 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 自己写的: class Solution: # findMode方法接受一个二叉树的根节点root,并返回一个列表,其中包含树中出现次数最多的值 def findMode(self, root: Optional[TreeNode]) -> List[int]: # 初始化一个队列,用于层次遍历二叉 阅读全文
posted @ 2024-05-19 15:34 Junior_bond 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 自己写的: class Solution: # 定义findWords方法,该方法接受一个字符串列表words作为参数 def findWords(self, words: List[str]) -> List[str]: # 定义三个字符串,分别包含键盘上三行的字母 str1 = "qwertyu 阅读全文
posted @ 2024-05-18 15:10 Junior_bond 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 自己写的: class Solution: def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: res = [] # 结果列表,用于存储每个nums1中元素在nums2中的下一个更大元素 num 阅读全文
posted @ 2024-05-17 14:59 Junior_bond 阅读(3) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示