上一页 1 2 3 4 5 6 7 8 ··· 14 下一页
摘要: 自己写的,哈希表,easy class Solution: def findTheDifference(self, s: str, t: str) -> str: # 创建一个空字典,用于存储字符出现的次数 mydict = {} # 遍历字符串s,统计每个字符出现的次数 for i in s: i 阅读全文
posted @ 2024-04-17 17:52 Junior_bond 阅读(11) 评论(0) 推荐(0)
摘要: 自己写的,easy class Solution: def firstUniqChar(self, s: str) -> int: mydict = {} # 创建一个空字典来存储每个字符的出现次数 for i in s: # 遍历给定的字符串 s if not mydict.get(i): # 如 阅读全文
posted @ 2024-04-16 20:36 Junior_bond 阅读(6) 评论(0) 推荐(0)
摘要: class Solution: def guessNumber(self, n: int) -> int: i = 1 # 初始猜测数为1 flag = True # 设置一个标志,用于控制循环 # 第一部分:使用倍增法寻找一个大于目标数字的边界值 while flag: # 使用 guess 函数 阅读全文
posted @ 2024-04-14 20:36 Junior_bond 阅读(25) 评论(0) 推荐(0)
摘要: 用二分法查找平方根: class Solution: def isPerfectSquare(self, num: int) -> bool: # 初始化左右边界 left = 1 right = num # 开始二分查找 while left <= right: # 计算中间值 mid = lef 阅读全文
posted @ 2024-04-13 14:50 Junior_bond 阅读(10) 评论(0) 推荐(0)
摘要: 自己写的: from typing import List class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: # 如果 nums1 或 nums2 为空列表,则返回空列表 if 阅读全文
posted @ 2024-04-12 15:09 Junior_bond 阅读(14) 评论(0) 推荐(0)
摘要: 自己写的: from typing import List # 导入List类型,用于函数参数和返回类型的注解 class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: # 初始化 阅读全文
posted @ 2024-04-11 14:28 Junior_bond 阅读(10) 评论(0) 推荐(0)
摘要: 自己写的,双指针,一次通过 class Solution: def reverseVowels(self, s: str) -> str: # 将输入的字符串转换为列表 s_list = list(s) # 定义元音字母列表 vowels = ['a', 'e', 'i', 'o', 'u', 'A 阅读全文
posted @ 2024-04-10 20:56 Junior_bond 阅读(11) 评论(0) 推荐(0)
摘要: 自己写的,这么简单? from typing import List class Solution: def reverseString(self, s: List[str]) -> None: n = len(s) # 获取字符串列表的长度 # 使用双指针法来反转字符串 # 初始化指针i指向字符串 阅读全文
posted @ 2024-04-09 22:27 Junior_bond 阅读(11) 评论(0) 推荐(0)
摘要: 自己写的,如果n对4可以整除。就让n除以4,循环往复 class Solution: def isPowerOfFour(self, n: int) -> bool: while n%4==0 and n>0: n//=4 return n==1 阅读全文
posted @ 2024-04-08 09:29 Junior_bond 阅读(5) 评论(0) 推荐(0)
摘要: 自己写的: from typing import List class Solution: def countBits(self, n: int) -> List[int]: # 创建一个空列表来存储结果 result = [] # 循环遍历从0到n的所有数字 for i in range(n + 阅读全文
posted @ 2024-04-07 14:18 Junior_bond 阅读(10) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 14 下一页