会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
yyyjw
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
3
4
5
6
7
8
9
10
11
···
14
下一页
2024年3月9日
leedcode-同构字符串
摘要: 自己写的: class Solution: def isIsomorphic(self, s: str, t: str) -> bool: # 使用 match 函数分别检查 s 到 t 和 t 到 s 的映射关系 res_a = self.match(s, t) res_b = self.matc
阅读全文
posted @ 2024-03-09 21:47 Junior_bond
阅读(21)
评论(0)
推荐(0)
2024年3月8日
leedcode-移除链表元素
摘要: 自己写的: # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solutio
阅读全文
posted @ 2024-03-08 22:38 Junior_bond
阅读(9)
评论(0)
推荐(0)
2024年3月7日
leetcode-快乐树
摘要: 自己写的: class Solution: def isHappy(self, n: int) -> bool: n_temp = n # 用n_temp保存当前的数字,以便迭代过程中使用 count = 0 # 用于计数,避免无限循环,设定最多迭代10次 while count < 10: # 最
阅读全文
posted @ 2024-03-07 15:36 Junior_bond
阅读(20)
评论(0)
推荐(0)
2024年3月6日
leedcode 位1的数量
摘要: 自己写的 class Solution: def hammingWeight(self, n: int) -> int: # 将整数 n 转换为二进制字符串,去除前缀 '0b' n_str = bin(n)[2:] # 用于存储 '1' 的列表 res_li = [] # 遍历二进制字符串的每一位
阅读全文
posted @ 2024-03-06 11:31 Junior_bond
阅读(7)
评论(0)
推荐(0)
leedcode 颠倒二进制
摘要: 使用bin函数 class Solution: def reverseBits(self, n: int) -> int: # 将整数 n 转换为二进制字符串,并用 左0 填充至32位 binary_str = bin(n)[2:].zfill(32) # 反转二进制字符串 reversed_str
阅读全文
posted @ 2024-03-06 10:49 Junior_bond
阅读(12)
评论(0)
推荐(0)
2024年3月5日
leedcode Excel 表列序号
摘要: 自己写的: class Solution: def titleToNumber(self, columnTitle: str) -> int: # 创建一个字典,将字母映射到它们在字母表中的位置 mydict = dict() for i in range(1, 27): mydict[chr(or
阅读全文
posted @ 2024-03-05 09:55 Junior_bond
阅读(15)
评论(0)
推荐(0)
2024年3月4日
leedcode 多数元素
摘要: 自己写的: class Solution: def majorityElement(self, nums): # 创建一个空字典用于存储数字和其出现次数 mydict = dict() # 遍历输入的列表 nums for i in nums: # 如果数字 i 不在字典中,将其添加到字典,并初始化
阅读全文
posted @ 2024-03-04 10:09 Junior_bond
阅读(6)
评论(0)
推荐(0)
2024年3月3日
leedcode 10进制转换成26进制
摘要: 10进制转换成26进制 A对应0:(正常的情况) class Solution: def convertToTitle(self, columnNumber: int) -> str: mydict = {} # 创建字典,映射数字到字母 for i in range(1, 27): mydict[
阅读全文
posted @ 2024-03-03 18:20 Junior_bond
阅读(22)
评论(0)
推荐(0)
2024年3月2日
leedcode 相交链表
摘要: 会超出时间限制: class Solution: def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]: cur_b=headB cur_a=headA while cur_b!=N
阅读全文
posted @ 2024-03-02 20:04 Junior_bond
阅读(9)
评论(0)
推荐(0)
2024年3月1日
leedcode 二叉树的后序遍历
摘要: 递归: class Solution: def __init__(self): # 初始化一个实例变量 res 用于存储遍历结果 self.res = list() def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]
阅读全文
posted @ 2024-03-01 16:46 Junior_bond
阅读(10)
评论(0)
推荐(0)
上一页
1
···
3
4
5
6
7
8
9
10
11
···
14
下一页
公告