2024年12月12日
摘要:
454. 四数相加 II - 力扣(LeetCode) 代码随想录 (programmercarl.com) 本题解题步骤: 首先定义 一个unordered_map(在python中为字典),key放a和b两数之和,value 放a和b两数之和出现的次数。 遍历大A和大B数组,统计两个数组元素之和
阅读全文
posted @ 2024-12-12 17:02
axuu
阅读(91)
推荐(0)
2024年12月6日
摘要:
解法1:暴力解法 class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): des = target - nums[i] if des in nums
阅读全文
posted @ 2024-12-06 13:43
axuu
阅读(21)
推荐(0)
摘要:
202. 快乐数 - 力扣(LeetCode) 解法1: (1)把数字n转换为字符串,从而得到每一位的数值。 事先不知道数字n有多少位。 (2)把每一次求平方和得到的数存到集合中,从而避免数字重复导致的循环。 class Solution: def calSquare(self, num): str
阅读全文
posted @ 2024-12-06 12:44
axuu
阅读(33)
推荐(0)
2024年12月4日
摘要:
文心一言: Python 的集合类型有一个 & 操作符,可以用来计算两个集合的交集。 class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: nums1_set = set(nu
阅读全文
posted @ 2024-12-04 20:25
axuu
阅读(18)
推荐(0)
2024年12月3日
摘要:
题目链接:https://leetcode.cn/problems/valid-anagram/description/ 解法1: class Solution: def isAnagram(self, s: str, t: str) -> bool: record = [0]*26 for i i
阅读全文
posted @ 2024-12-03 21:09
axuu
阅读(22)
推荐(0)
摘要:
https://www.programmercarl.com/%E5%93%88%E5%B8%8C%E8%A1%A8%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html#%E5%B8%B8%E8%A7%81%E7%9A%84%E4%B8%89%E7%A7%8D%E5%9
阅读全文
posted @ 2024-12-03 20:58
axuu
阅读(23)
推荐(0)
摘要:
题目链接: https://leetcode.cn/problems/linked-list-cycle-ii/description/ 题解链接: https://www.programmercarl.com/0142.%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8II.
阅读全文
posted @ 2024-12-03 11:30
axuu
阅读(22)
推荐(0)
2024年12月2日
摘要:
面试题 02.07. 链表相交 - 力扣(LeetCode) 文心一言: 首先,getIntersectionNode 方法中调用了 self.getIntersectionNode2(headA, headB) 等,但这些调用没有使用它们的返回值。getIntersectionNode2 方法返回
阅读全文
posted @ 2024-12-02 00:07
axuu
阅读(24)
推荐(0)
2024年11月27日
摘要:
24. 两两交换链表中的节点 - 力扣(LeetCode) 代码随想录 递归方式:没有想到 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.va
阅读全文
posted @ 2024-11-27 09:45
axuu
阅读(28)
推荐(0)
2024年11月26日
摘要:
206. 反转链表 - 力扣(LeetCode) 代码随想录 解法1:双指针法 解法2:递归法(代码如下所示) # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None):
阅读全文
posted @ 2024-11-26 16:55
axuu
阅读(22)
推荐(0)