原创 [leetcode] 398. Random Pick Index 解題報告

題目鏈接:https://leetcode.com/problems/random-pick-index/ Given an array of integers with possible duplicates, randomly o

原创 [leetcode] 400. Nth Digit 解題報告

題目鏈接:https://leetcode.com/problems/nth-digit/ Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7

原创 [leetcode] 418. Sentence Screen Fitting 解題報告

題目鏈接: https://leetcode.com/problems/sentence-screen-fitting/ Given a rows x cols screen and a sentence represented by

原创 數組中兩個元素異或求最大值

給一個整數數組,求數組中兩個元素異或的最大值. 思路:naive的做法是兩兩異或求最大值,時間複雜度爲O(n*n),但是還有一種O(n)的解法,利用字典樹Trie來實現. 其思路是利用數組中的每個元素二進制表示形式建一棵樹,我看到網上大

原创 [leetcode] 406. Queue Reconstruction by Height 解題報告

題目鏈接:https://leetcode.com/problems/queue-reconstruction-by-height/ Suppose you have a random list of people standing

原创 [leetcode] 408. Valid Word Abbreviation 解題報告

題目鏈接:https://leetcode.com/problems/valid-word-abbreviation/ Given a non-empty string s and an abbreviation abbr, ret

原创 [leetcode] 416. Partition Equal Subset Sum 解題報告

題目鏈接:https://leetcode.com/problems/partition-equal-subset-sum/ Given a non-empty array containing only positive integ

原创 [leetcode] 449. Serialize and Deserialize BST 解題報告

題目鏈接:https://leetcode.com/problems/serialize-and-deserialize-bst/ Serialization is the process of converting a data s

原创 [leetcode] 455. Assign Cookies 解題報告

題目鏈接:https://leetcode.com/problems/assign-cookies/ Assume you are an awesome parent and want to give your children so

原创 [leetcode] 421. Maximum XOR of Two Numbers in an Array 解題報告

題目鏈接: https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/ Given a non-empty array of numbers, a0, a

原创 [leetcode] 462. Minimum Moves to Equal Array Elements II 解題報告

題目鏈接: https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ Given a non-empty integer array, find t

原创 [leetcode] 447. Number of Boomerangs 解題報告

題目鏈接: https://leetcode.com/problems/number-of-boomerangs/ Given n points in the plane that are all pairwise distinct,

原创 [leetcode] 437. Path Sum III 解題報告

題目鏈接: https://leetcode.com/problems/path-sum-iii/ You are given a binary tree in which each node contains an integer

原创 clockwise print binary search tree

給一個二叉樹, 順時針打印出所有的節點, 例如: 應該打印: 20, 8, 4, 10, 14, 25, 22 思路: 可以分爲三步打印: 1. 打印左邊界, 最後一個葉子節點不打印 2. 打印所有葉子結點 3. 打印右邊界, 根和

原创 [leetcode] 463. Island Perimeter 解題報告

題目鏈接: https://leetcode.com/problems/island-perimeter/ You are given a map in form of a two-dimensional integer gr