Note: The Listed platform will permanently shut down December 31, 2026. Your data published on Listed will still be available in your personal Standard Notes account. Learn more

if helper return vs return helper
if helper return vs return helper 以这一题为例 211. 添加与搜索单词 - 数据结构设计 我们看 helper  function里面有一个 if self.helper(word, node.next[i], k+1): return True 还有一个 return self.helper(word, node.next[ch], k+1) 那么什么时候是  if helper return True   什么时候是 return helper  答案是: 如例子里面 那么什么时候是  if helper return True   for  loop里面有很多可能性,有的return True, 有的 return False 其实我关心只是,是否有一个True 什么时候是 return helper  就是我接下来只有一种可能,所以可以就 return helper  class Trie: def __init__(self): self.next = {} ...
Read post
NSum
NSum Leetcode 里面有一个NSum问题 1. 两数之和 15. 三数之和 18. 四数之和 解法的话 两数之和就是用 2 pointer class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: left = 0 n = len(nums) right = n-1 res = [] while left < right: l = nums[left] r = nums[right] if l+r == target: res.append([left,right]) left += 1 right -= 1 while nums[left] == nums[left-...
Read post