摘要:
自己写的,哈希表,easy class Solution: def findTheDifference(self, s: str, t: str) -> str: # 创建一个空字典,用于存储字符出现的次数 mydict = {} # 遍历字符串s,统计每个字符出现的次数 for i in s: i 阅读全文
摘要:
自己写的,easy class Solution: def firstUniqChar(self, s: str) -> int: mydict = {} # 创建一个空字典来存储每个字符的出现次数 for i in s: # 遍历给定的字符串 s if not mydict.get(i): # 如 阅读全文
摘要:
用二分法查找平方根: class Solution: def isPerfectSquare(self, num: int) -> bool: # 初始化左右边界 left = 1 right = num # 开始二分查找 while left <= right: # 计算中间值 mid = lef 阅读全文
摘要:
自己写的: from typing import List class Solution: def countBits(self, n: int) -> List[int]: # 创建一个空列表来存储结果 result = [] # 循环遍历从0到n的所有数字 for i in range(n + 阅读全文