摘要:
class Solution: def countSegments(self, s: str) -> int: n = len(s) # 如果字符串长度为1且不是空格,则只有一个段 if n == 1 and s[0] != ' ': return 1 # 如果字符串长度为1且是空格,则没有段 if 阅读全文
摘要:
自己写的,用时很长 from typing import List class Solution: def thirdMax(self, nums: List[int]) -> int: # 计算输入列表的长度 n = len(nums) # 对列表进行冒泡排序,将较大的元素排在前面 for i i 阅读全文
摘要:
自己写的: class Solution: def longestPalindrome(self, s: str) -> int: count = 0 # 用于计算最长回文串的长度 hash = {} # 用于统计每个字符出现的次数的字典 # 统计每个字符出现的次数 for i in s: if n 阅读全文
摘要:
自己写的,调用了combinations函数: from itertools import combinations from typing import List class Solution: def readBinaryWatch(self, turnedOn: int) -> List[st 阅读全文
摘要:
自己写的,有点麻烦 class Solution: def isSubsequence(self, s: str, t: str) -> bool: # 第一步先验证s是t的无序子序列 # 使用字典记录t中每个字符的出现次数 mydict = dict() for i in t: if not my 阅读全文