原创 [LeetCode]208. Implement Trie (Prefix Tree)

Problem Description [https://leetcode.com/problems/implement-trie-prefix-tree/] Implement a trie with insert, sear

原创 KMP的思路與實現

思路 我就不提爲啥有KMP和KMP的原理了,這段跳過。。。 首先計算next數組,算法如下: 輸入:String m; 輸出:int[] next; 1.next[0]=0; 2.計算next[i]: 從j=next[i-

原创 [LeetCode]120. Triangle

Problem Description [https://leetcode.com/problems/triangle/] Given a triangle, find the minimum path sum from top

原创 [LeetCode]109. Convert Sorted List to Binary Search Tree

Problem Description [https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/] Given a singly link

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

Problem Description [https://leetcode.com/problems/powx-n/] Implement pow(x, n). 思路 不明白這種題爲什麼會是mid的。。。 Code packag

原创 [LeetCode]309. Best Time to Buy and Sell Stock with Cooldown

Problem Description [https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/] Say you have an

原创 [LeetCode]114. Flatten Binary Tree to Linked List

Problem Description Given a binary tree, flatten it to a linked list in-place. [https://leetcode.com/problems/flat

原创 [LeetCode]22. Generate Parentheses

Problem Description [https://leetcode.com/problems/generate-parentheses/] Given n pairs of parentheses, write a fu

原创 [LeetCode]31. Next Permutation

Problem Description [https://leetcode.com/problems/next-permutation/] Implement next permutation, which rearranges

原创 [LeetCode]230. Kth Smallest Element in a BST

Problem Description [https://leetcode.com/problems/kth-smallest-element-in-a-bst/] Given a binary search tree, wri

原创 [LeetCode]63. Unique Paths II

Problem Description [https://leetcode.com/problems/unique-paths-ii/] Follow up for “Unique Paths”: Now consider if

原创 [LeetCode]130. Surrounded Regions

Problem Description [https://leetcode.com/problems/surrounded-regions/] Given a 2D board containing ‘X’ and ‘O’, c

原创 生產者消費者模式

描述 簡單的一個例子: 如果你是造東西的廠商,你製造的東西需要有人來買對吧。 會有顧客(一般顧客)直接去廠子裏去拿麼? 你會直接把東西寄給顧客麼?(直銷除外) 很少會有這樣的情況。 所以我們需要商場。 生產者消費者模式

原创 [LeetCode]94. Binary Tree Inorder Traversal

Problem Description [https://leetcode.com/problems/binary-tree-inorder-traversal/] Given a binary tree, return the

原创 [LeetCode]29. Divide Two Integers

Problem Description [https://leetcode.com/problems/divide-two-integers/] Divide two integers without using multipl