原创 LeetCode.79. Word Search

https://leetcode.com/problems/word-search/ 這道題給了我們一個字符二維數組,再給我們一個字符串,問這個字符串是否存在於字符數組中。必須是連續的上下左右相鄰,當然也不能重複訪問已經訪問過的節點。

原创 LeetCode.33. Search in Rotated Sorted Array

https://leetcode.com/problems/search-in-rotated-sorted-array/ 判斷當前數組的中間元素是否小於最右邊的元素,如果小於,說明右半部分是有序的。否則說明左半部分是有序的。 如果右

原创 LeetCode.637. Average of Levels in Binary Tree

https://leetcode.com/contest/leetcode-weekly-contest-40/problems/average-of-levels-in-binary-tree/ 這一題讓我們計算每一層的平均數,遞歸

原创 LeetCode.31. Next Permutation

https://leetcode.com/problems/next-permutation/ class Solution { public void nextPermutation(int[] nums) {

原创 LeetCode.322. Coin Change

https://leetcode.com/problems/coin-change/ 這裏的dp是這樣記錄數據的。 記錄amount = 1, 2, 3, 4, …, n - 1,需要硬幣的最小值。 那麼amount = n的最小值,

原创 LeetCode.223. Rectangle Area

https://leetcode.com/problems/rectangle-area/ 這道題,先判斷是否相交,相交的話,就是兩個矩形面積減去重疊的面積。不相交,就是兩個矩形的面積。 class Solution { pu

原创 LeetCode.151. Reverse Words in a String

https://leetcode.com/problems/reverse-words-in-a-string/ 先從頭到尾挨個字符的讀取,將每個單詞都反轉,順便將每個單詞都加入一個list 然後從list裏面逆序的取出來拼最後的字符

原创 LeetCode.3. Longest Substring Without Repeating Characters

https://leetcode.com/problems/longest-substring-without-repeating-characters/ 使用兩個指針i,j作爲一個窗口,並且用一個集合來記錄已經記住的字符。 判斷j所

原创 LeetCode.617. Merge Two Binary Trees

https://leetcode.com/problems/merge-two-binary-trees/ class Solution { public TreeNode mergeTrees(TreeNode t1, Tr

原创 LeetCode.344. Reverse String

https://leetcode.com/problems/reverse-string/ 這題很簡單,我下面的做法不是很好,非常慢…… 其實也可以轉成char[],然後交換位置這樣可能會快點 class Solution {

原创 LeetCode.104. Maximum Depth of Binary Tree

https://leetcode.com/problems/maximum-depth-of-binary-tree/ class Solution { static int maxDepth = 0;

原创 LeetCode.654. Maximum Binary Tree

https://leetcode.com/problems/maximum-binary-tree/ 遞歸就完事了 class Solution { public TreeNode constructMaximumBinary

原创 LeetCode.50. Pow(x, n)

https://leetcode.com/problems/powx-n/ 我的想法是使用一個map來存住之前計算的值,比如要算2^10 那麼就算出 2^5 * 2^5 就要算出 2^2 * 2^2 * 2 以下有兩個方法,方法1,

原创 LeetCode.17. Letter Combinations of a Phone Number

https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 這道題並不難 第一次按鍵,就將每個char都以string存在一個list裏面 後面的每按一下,

原创 快速排序

思路 快速排序將數組A通過原地交換的方法將數組分成兩個區域,一個區域的所有元素都小於等於p,另一個區域所有元素都大於等於p。然後再遞歸的處理這兩個區域。 如上圖所示: 1.選取6作爲基準,將小於等於6的數都移動到它的左側,大於等於6