原创 leetcode-5.3[172. 階乘後的零、189. 旋轉數組、5400. 旅行終點站](python實現)

題目1 題解1 class Solution: def trailingZeroes(self, n: int) -> int: """ 末尾的0來自因子2和5 ,只有有5,就一定

原创 leetcode-5.2[171. Excel表列序號、168. Excel表列名稱、167. 兩數之和 II - 輸入有序數組](python實現)

題目1 題解1 class Solution: def titleToNumber(self, s: str) -> int: res = 0 for index, word in enu

原创 leetcode-4.28[107. 二叉樹的層次遍歷 II、101. 對稱二叉樹、104. 二叉樹的最大深度](python解法)

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

原创 leetcode-4.29[111. 二叉樹的最小深度、108. 將有序數組轉換爲二叉搜索樹、110. 平衡二叉樹](python解法)

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

原创 leetcode-4.30[112. 路徑總和、118. 楊輝三角、121. 買賣股票的最佳時機](python實現)

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

原创 leetcode-4.27[83. 刪除排序鏈表中的重複元素、100. 相同的樹](python解法)

題目1 題解1 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x

原创 leetcode-4.26[70. 爬樓梯、69. x 的平方根、67. 二進制求和](python解法)

題目1 題解1 class Solution: """ 1. 子問題: DP[i] 到第i元素最多的爬取方式 2. 子方法之間的關係: 第 i 階可以由以下兩種方

原创 leetcode-4.25[66. 加一、58. 最後一個單詞的長度、53. 最大子序和](python解法)

題目1 題解1 class Solution: def plusOne(self, digits: List[int]) -> List[int]: n = len(digits)-1 d

原创 leetcode-4.23[7. 整數反轉、9. 迴文數、13. 羅馬數字轉整數](python解法)

題目1 題解1 class Solution: def reverse(self, x: int) -> int: num, res = abs(x), 0 of = (1 << 31)

原创 leetcode-4.24[35. 搜索插入位置、28. 實現 strStr()、27. 移除元素](python解法)

題目1 題解1 class Solution: def searchInsert(self, nums: List[int], target: int) -> int: for index, num in

原创 leetcode-4.21[169. 多數元素、160. 相交鏈表、155. 最小棧](python解法)

題目1 題解1 from queue import PriorityQueue class Solution: def majorityElement(self, nums: List[int]) -> int:

原创 leetcode-4.22[215. 數組中的第K個最大元素、206. 反轉鏈表、198. 打家劫舍](python解法)

題目1 題目2 class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: # 遞歸實現快速排序 d

原创 排序算法原理與實現[冒泡、選擇、插入、快速、哈希、計數](python版)

1. 冒泡排序: 原理 冒泡排序算法的基本原理就是比較相鄰兩個數字的大小。將兩個數中比較大的那個數交換到靠後的位置,不斷交換下去就可以將最大的那兩個數放到隊列的尾部。然後重頭再次交換)(交換list.lenght-1次),直

原创 二叉樹-( 二叉樹的層次遍歷) 方法1 對層迭代解法、方法2 雙向隊列

方法1 # -*- coding:utf-8 -*- """ Author: leadingme Mail:[email protected] MyWebsite:leadingme.top """ # 二叉樹的層次遍歷 ""

原创 leetcode-4.13[355. 設計推特](python解法)

題目 題解 from collections import defaultdict class Twitter: def __init__(self): """ Initialize yo