Leetcode 2021-04-09
154.find-minimum-in-rotated-sorted-array-ii
154.find-minimum-in-rotated-sorted-array-ii
力扣 LeetCode
154. 寻找旋转排序数组中的最小值 II - 力扣(LeetCode)
已知一个长度为 n 的数组,预先按照升序排列,经由 1 到 n 次 旋转 后,得到输入数组。例如,原数组 nums = [0,1,4,4,5,6,7] 在变化后可能得到: 若旋转 4 次,则可以得到 [4,5,6,7,0,1,4] 若旋转 7 次,则可以得到 [0,1,4,4,5,6,7] 注意,数组 [a[0], a[1], a[2], ..., a[n-1]] 旋转一次 的结果为数组 [a[n-1], a[0], a[1], a[2], ..., a[n-2]] 。 给你一个可能存在 重复 元素值的数组…
Leetcode 2021-04-10
263.ugly-number
263.ugly-number
力扣 LeetCode
263. 丑数 - 力扣(LeetCode)
编写一个程序判断给定的数是否为丑数。 丑数就是只包含质因数 2, 3, 5 的正整数。 示例 1: 输入: 6 输出: true 解释: 6 = 2 × 3 示例 2: 输入: 8 输出: true 解释: 8 = 2 × 2 × 2 示例 3: 输入: 14 输出: false 解释: 14 不是丑数,因为它包含了另外一个质因数 7。 说明: 1 是丑数。 输入不会超过 32 位有符号整数的范围: [−231, 231 − 1]。。263. Ugly Number: Given an integer n…
Leetcode 2021-04-11
264.ugly-number-ii
264.ugly-number-ii
力扣 LeetCode
264. 丑数 II - 力扣(LeetCode)
编写一个程序,找出第 n 个丑数。 丑数就是质因数只包含 2, 3, 5 的正整数。 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。 说明: 1 是丑数。 n 不超过1690。。264. Ugly Number II: Given an integer n, return the nth ugly number. Ugly number is a positive number whose prime factors…
Leetcode 2021-04-12
179.largest-number
179.largest-number
力扣 LeetCode
179. 最大数 - 力扣(LeetCode)
给定一组非负整数 nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。 注意:输出结果可能非常大,所以你需要返回一个字符串而不是整数。 示例 1: 输入:nums = [10,2] 输出:"210" 示例 2: 输入:nums = [3,30,34,5,9] 输出:"9534330" 示例 3: 输入:nums = [1] 输出:"1" 示例 4: 输入:nums = [10] 输出:"10" 提示: 1 <= nums.length <= 100 0 <= nums[i] <= 109。179.…
Leetcode 2021-04-13
🟢 783.minimum-distance-between-bst-nodes
#tree #depth-first-search #recursion
Given the
🟢 783.minimum-distance-between-bst-nodes
#tree #depth-first-search #recursion
Given the
root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.
Input: root = [4,2,6,1,3]
Output: 1
Leetcode 2021-04-14
🟡 208.implement-trie-prefix-tree
#design #trie
A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.
🟡 208.implement-trie-prefix-tree
#design #trie
A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.
Input
["Trie", "insert", "search", "search", "startsWith", "insert", "search"]
[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]
Output
[null, null, true, false, true, null, true]
Explanation
Trie trie = new Trie();
trie.insert("apple");
trie.search("apple"); // return True
trie.search("app"); // return False
trie.startsWith("app"); // return True
trie.insert("app");
trie.search("app"); // return True