原创 【Leetcode】830. 較大分組的位置(Positions of Large Groups)

Leetcode - 830 Positions of Large Groups (Easy) 題目描述:給定一個字符串由連續相同的字母組成,找出連續字母數量超過 3 的起始位置。 Input: "abbxxxxzzy" Outp

原创 【Leetcode】1018. 可被 5 整除的二進制前綴(Binary Prefix Divisible By 5)

Leetcode - 1018 Binary Prefix Divisible By 5 (Easy) 題目描述:給定一個由 0 和 1 組成的數組,定義 Ni 爲 從 A[0] 到 A[i] 的第 i 個子數組被解釋爲一個二進制

原创 【Leetcode】23. 合併 k 個有序鏈表(Merge k Sorted Lists)

Leetcode - 23 Merge k Sorted Lists (Hard) Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4->4->5->6 解

原创 【Leetcode】33. 搜索旋轉排序數組(Search in Rotated Sorted Array)

Leetcode - 33 Search in Rotated Sorted Array (Medium) 題目描述:給定一個旋轉的有序數組,例如有序數組 [0,1,2,4,5,6,7] 經一次旋轉後可得 [4,5,6,7,0,

原创 【Leetcode】36. 有效的數獨(Valid Sudoku)

Leetcode - 36 Valid Sudoku (Medium) 題目描述:給定一個 9 × 9 的不完整數獨數組,判定是否合法。 解題思路:判斷每一行、每一列和每個 3 × 3 單元格是否有重複的數字。 public bo

原创 【Leetcode】15. 三數之和(3Sum)

Leetcode - 15 3Sum (Medium) 題目描述:找出數組中三數和爲 0 的組合。 Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [

原创 【Leetcode】48. 旋轉圖像(Rotate Image)

Leetcode - 48 Rotate Image (Medium) 題目描述:將一個 n × n 的矩陣旋轉 90°,不能使用額外的輔助空間。 Given input matrix = [ [1,2,3], [4,5

原创 【Leetcode】46. 全排列(Permutations)

Leetcode - 46 Permutations (Medium) 題目描述: 給定無重複的整數序列,返回所有全排列的可能。 Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [

原创 【Leetcode】41. 缺失的第一個正整數(First Missing Positive)

Leetcode - 41 First Missing Positive (Hard) Input: [3,4,-1,1] Output: 2 public int firstMissingPositive(int[] nums

原创 【Leetcode】11. 盛最多水的容器(Container With Most Water)

Leetcode - 11 Container With Most Water (Medium) 題目描述:找出兩條線,使得構成的容器能夠容納最多的水。 public int maxArea(int[] height) {

原创 【Leetcode】5. 最長迴文子串(Longest Palindromic Substring)

Leetcode - 5 Longest Palindromic Substring (Medium) Input: "babad" Output: "bab" Note: "aba" is also a valid answer

原创 【Leetcode】7. 整數反轉(Reverse Integer)

Leetcode - 7 Reverse Integer (Easy) 題目描述:反轉一個 32 位有符號的整數。 Input: -123 Output: -321 解題思路:注意整型範圍越界。 public int rever

原创 【Leetcode】121. 最佳買賣股票的時間 I(Best Time to Buy and Sell Stock)

Leetcode - 121 Best Time to Buy and Sell Stock (Easy) 題目描述:最多交易一次。 解法一:DP public int maxProfit(int[] prices) {

原创 【Leetcode】10. 正則表達式匹配(Regular Expression Matching)

Leetcode - 10 Regular Expression Matching (Hard) 題目描述:. 表示任意字符,* 表示它前面的字符可以出現任意次(包含 0 次)。 Input: s = "aab" p = "c*a

原创 【棧和隊列】設計一個有 getMin 功能的棧

題目 實現一個特殊的棧,在實現棧的基本功能的基礎上,再實現返回棧中最小元素的操作。 要求 pop、push、getMin 操作的時間複雜度都是 O(1) 設計的棧類型可以使用現成的棧結構 思路一 使用兩個棧,一個棧保存當前棧中