原创 【Lintcode】442. Implement Trie (Prefix Tree)

題目地址: https://www.lintcode.com/problem/implement-trie-prefix-tree/description 實現字典樹Trie,題目保證所有字符串都由a∼za\sim za∼z組成。

原创 【Lintcode】750. Portal

題目地址: https://www.lintcode.com/problem/portal/description 給定一個二維矩陣,SSS代表出發點,EEE代表出口,∗*∗代表空地,#\##代表牆壁。問從出發點到出口最少要多少步

原创 【Leetcode】285. Inorder Successor in BST

題目地址: https://leetcode.com/problems/inorder-successor-in-bst/ 給定一棵BST,再給定其中一節點ppp,求其中序遍歷的後繼。 首先後繼肯定是比ppp大的,並且是所有比pp

原创 【Leetcode】173. Binary Search Tree Iterator

題目地址: https://leetcode.com/problems/binary-search-tree-iterator/ 給定一棵BST,設計其中序遍歷的迭代器。 主要思想是模擬非遞歸二叉樹中序遍歷的過程。回想一下非遞歸中

原创 【Lintcode】1154. Attendance Judgment

題目地址: https://www.lintcode.com/problem/attendance-judgment/description 給定一個字符串,裏面只含有A,D,LA,D,LA,D,L三種字母(也可以缺其中的某個或者

原创 【Leetcode】339. Nested List Weight Sum

題目地址: https://leetcode.com/problems/nested-list-weight-sum/ 有一個NestedInteger類,它要麼是個整數,要麼是NestedInteger組成的list。現在給定一

原创 【Leetcode】280. Wiggle Sort

題目地址: https://leetcode.com/problems/wiggle-sort/ 給定一個數組AAA,重排之使得A[0]≤A[1]≥A[2]≤A[3]≥A[4]...A[0]\le A[1] \ge A[2]\le

原创 【Lintcode】402. Continuous Subarray Sum

題目地址: https://www.lintcode.com/problem/continuous-subarray-sum/description 給定一個數組,求其最大和連續子列,返回區間起點和終點下標。若有若干不同區間和都是

原创 【Leetcode】1436. Destination City

題目地址: https://leetcode.com/problems/destination-city/ 給定一個數組,每一行含兩個字符串分別代表兩個城市,含義是第一個城市可以直達第二個城市。求那個只作爲終點不作爲起點的城市。題

原创 【Leetcode】409. Longest Palindrome

題目地址: https://leetcode.com/problems/longest-palindrome/ 給定一個字符串,可以從其中挑選任意多字符,問能組成的最長迴文字符串的長度。 可以先統計字符串中各個字符出現的次數,出現

原创 【Leetcode】346. Moving Average from Data Stream

題目地址: https://leetcode.com/problems/moving-average-from-data-stream/ 設計一個數據結構,可以實現下列操作: 1、添加一個數; 2、保持數據結構存儲的數的個數小於一

原创 【Leetcode】1065. Index Pairs of a String

題目地址: https://leetcode.com/problems/index-pairs-of-a-string/ 給定一個字符串sss,再給定一個字符串數組,如果數組中一個字符串是sss的子串,那麼就記下該子串在sss中的

原创 【Leetcode】266. Palindrome Permutation

題目地址: https://leetcode.com/problems/palindrome-permutation/ 判斷一個字符串是否可以通過適當排列裏面的字符成爲一個迴文串。 當且僅當這個字符串出現奇數次的字符不超過111個

原创 【Leetcode】305. Number of Islands II

題目地址: https://leetcode.com/problems/number-of-islands-ii/ 給定一個二維零矩陣,再給點一個數組,數組每個位置是個長爲222的整數數組,是矩陣裏的一個座標。遍歷數組的同時,會把

原创 【Leetcode】648. Replace Words

題目地址: https://leetcode.com/problems/replace-words/ 給定一個字符串數組,再給定一個英文句子,句子裏只含英文單詞,並且以空格分隔。如果句子中的某個單詞以數組中某個字符串爲前綴,則將其