原创 leetcode-5.15[560. 和爲K的子數組、1337. 方陣中戰鬥力最弱的 K 行](python實現)

題目1 題解1 class Solution: def subarraySum(self, nums: List[int], k: int) -> int: hash={0:1} sum=

原创 leetcode-5.16[1022. 從根到葉的二進制數之和、633. 平方數之和、371. 兩整數之和](python實現)

題目1 題解1 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x

原创 leetcode-5.18[985. 查詢後的偶數和、404. 左葉子之和](python實現)

題目1 題解1 class Solution: def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) -> List[int]:

原创 leetcode-5.12[263. 醜數、884. 兩句話中的不常見單詞、929. 獨特的電子郵件地址](python實現)

題目1 題解1 class Solution: def isUgly(self, num: int) -> bool: """ 貪心算法 """ #

原创 leetcode-5.13[867. 轉置矩陣、669. 修剪二叉搜索樹、1029. 兩地調度](python實現)

題目1 題解1 class Solution: def transpose(self, A: List[List[int]]) -> List[List[int]]: n = len(A[0])

原创 leetcode-5.14[414. 第三大的數、709. 轉換成小寫字母、766. 託普利茨矩陣](python實現)

題目1 題解1 class Solution: def thirdMax(self, nums: List[int]) -> int: # 集合去重 nums = list(set(num

原创 leetcode-5.7[LCP 06. 拿硬幣、572. 另一個樹的子樹、LCP 07. 傳遞信息](python實現)

題目1 題解1 class Solution: def minCount(self, coins: List[int]) -> int: """ 貪心算法 """

原创 leetcode-5.9[680. 驗證迴文字符串 II、941. 有效的山脈數組、1037. 有效的迴旋鏢](python實現)

題目1 題解1 class Solution: def validPalindrome(self, s: str) -> bool: l, r = 0, len(s) - 1 while

原创 leetcode-5.11[804. 唯一摩爾斯密碼詞、1207. 獨一無二的出現次數](python實現)

題目1 題解1 class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: Morse = [".-","

原创 leetcode-5.8[367. 有效的完全平方數、290. 單詞規律、914. 卡牌分組](python實現)

題目1 題解1 class Solution: def isPerfectSquare(self, num: int) -> bool: """ 二分查找 """

原创 leetcode-5.10[965. 單值二叉樹、242. 有效的字母異位詞、*236. 二叉樹的最近公共祖先](python實現)

題目1 題解1 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x

原创 leetcode-5.6[219. 存在重複元素 II、225. 用隊列實現棧、226. 翻轉二叉樹](python實現)

題目1 題解1 class Solution: def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: seen = lis

原创 leetcode-5.4[191. 位1的個數、202. 快樂數、203. 移除鏈表元素](python實現)

題目1 題解1 class Solution: def hammingWeight(self, n: int) -> int: sum = 0 # 每次減去一個1,然後與原值相與,得到的值

原创 leetcode-5.5[217. 存在重複元素、205. 同構字符串、204. 計數質數](python實現)

題目1 題解1 class Solution: def containsDuplicate(self, nums: List[int]) -> bool: seen = set() i =

原创 leetcode-5.1[136. 只出現一次的數字、122. 買賣股票的最佳時機 II、125. 驗證迴文串](python實現)

題目1 題解1 class Solution: """ 時間複雜度: O(n^2) 空間複雜度: O(n) """ def singleNumber(self, nums: