随笔分类 - leetcode
摘要:问题: 将给定正整数n,拆成多个数。(使得这些数之和=n) 这些数之积最大是多少。 Example 1: Input: n = 2 Output: 1 Explanation: 2 = 1 + 1, 1 × 1 = 1. Example 2: Input: n = 10 Output: 36 Exp
阅读全文
posted @ 2021-04-14 13:56
habibah_chang
摘要:问题: 给定多个字符串定义:某个小写字母==(!=)另一个小写字母 求这些定义中,有互相矛盾的情况吗? 有矛盾,返回false,否则返回true。 Example 1: Input: ["a==b","b!=a"] Output: false Explanation: If we assign sa
阅读全文
posted @ 2021-04-13 19:37
habibah_chang
摘要:问题: 给定一个字符串,表示一个由+-*三种运算符组成的算式。 求给运算式任意加括号,使得计算优先顺序变化。 所得所有结果的可能。 Example 1: Input: expression = "2-1-1" Output: [0,2] Explanation: ((2-1)-1) = 0 (2-(
阅读全文
posted @ 2021-04-11 16:14
habibah_chang
摘要:问题: 求数组中第k大的元素。 Example 1: Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 Example 2: Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4 Constraints: 1 <
阅读全文
posted @ 2021-04-11 14:36
habibah_chang
摘要:问题: 给定两个int数组,代表两个数位数值的列表。 从两个数组中,按照已有的顺序选取数位数值, 组成一个新的数,长度为k 求能构成的数最大为? Example 1: Input: nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5 Output: [9,
阅读全文
posted @ 2021-04-09 20:17
habibah_chang
摘要:问题: 给定n个初始状态为off的灯, 第1次,按 1*i 号灯的开关。 第2次,按 2*i 号灯的开关。 ... 第n次,按 n 号灯的开关。 求最后on的灯共有几个。 Example 1: Input: n = 3 Output: 1 Explanation: At first, the thr
阅读全文
posted @ 2021-04-09 13:18
habibah_chang
摘要:问题: 给n个石子,由你开始选取,和你的朋友轮流进行。 每次选取,可以选取1~3个石子, 最后一个取完石子的人获胜,返回你是否能赢得胜利。 Example 1: Input: n = 4 Output: false Explanation: These are the possible outcom
阅读全文
posted @ 2021-04-09 12:35
habibah_chang
摘要:问题: 求0~num 每个数的二进制中含有 1 的个数。 Example 1: Input: num = 2 Output: [0,1,1] Explanation: 0 --> 0 1 --> 1 2 --> 10 Example 2: Input: num = 5 Output: [0,1,1,
阅读全文
posted @ 2021-04-07 15:48
habibah_chang
摘要:问题: 去除有序链表中重复的节点。 Example 1: Input: head = [1,1,2] Output: [1,2] Example 2: Input: head = [1,1,2,3,3] Output: [1,2,3] Constraints: The number of nodes
阅读全文
posted @ 2021-04-07 14:49
habibah_chang
摘要:问题: 将数组中的0移到末尾。 Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] Constraints: 1 <= nums.length <= 1
阅读全文
posted @ 2021-04-07 14:39
habibah_chang
摘要:问题: 删除数组中的元素val。 返回剩下数组的size。 Example 1: Input: nums = [3,2,2,3], val = 3 Output: 2, nums = [2,2] Explanation: Your function should return length = 2,
阅读全文
posted @ 2021-04-07 14:17
habibah_chang
摘要:问题: 去除有序数组中重复的数字。 Example 1: Input: nums = [1,1,2] Output: 2, nums = [1,2] Explanation: Your function should return length = 2, with the first two ele
阅读全文
posted @ 2021-04-07 13:59
habibah_chang
摘要:问题: 给定一个二维数组, 求给定区间围成矩形的和。 Example 1: Input ["NumMatrix", "sumRegion", "sumRegion", "sumRegion"] [[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5],
阅读全文
posted @ 2021-04-06 15:17
habibah_chang
摘要:类似问题: 382. Linked List Random Node 问题: 给定一组数(可能有重复的数字), 求随机取得数字=target的index。 ⚠️ 注意:取得每个数的概率要相同。 Example 1: Input ["Solution", "pick", "pick", "pick"]
阅读全文
posted @ 2021-04-06 14:36
habibah_chang
摘要:问题: 给定一个链表,求随机抽取一个元素。 使得每个元素被取出的概率相同。 Example 1: Input ["Solution", "getRandom", "getRandom", "getRandom", "getRandom", "getRandom"] [[[1, 2, 3]], [],
阅读全文
posted @ 2021-04-06 14:02
habibah_chang
摘要:类似解法问题(index符号标记法) 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array 问题: 给定size=n的数组,记录1~n。 其中存在某个数字重复,占用另一个数字的空间,导致漏
阅读全文
posted @ 2021-04-05 10:50
habibah_chang
摘要:问题: 勇士救公主问题。 勇士从左上角[0,0]出发,要到达右下角[n-1,m-1]公主所在。 只能向右or向下移动。 格子上的数字代表:加减血。 若到达某个格子勇士血量<1那么,勇士立即死亡。游戏失败。 求,至少在出发时,勇士的初始血量是多少。 Example 1: Input: dungeon
阅读全文
posted @ 2021-04-01 18:08
habibah_chang
摘要:问题: 求第n个ugly number 定义:ugly number:只由2or3or5作为因数求得。 1为第一个ugly number。 Example 1: Input: n = 10 Output: 12 Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12
阅读全文
posted @ 2021-04-01 14:00
habibah_chang
摘要:问题: 给定字符串s,匹配串t 求s中匹配t的方法有多少种。 匹配:s中存在t的序列。 Example 1: Input: s = "rabbbit", t = "rabbit" Output: 3 Explanation: As shown below, there are 3 ways you
阅读全文
posted @ 2021-04-01 13:34
habibah_chang
摘要:问题: 求a^b%base的值。 a为int型数 b为int数组,例如[1,2,3,4]代表:b=1234 base=1337。 Example 1: Input: a = 2, b = [3] Output: 8 Example 2: Input: a = 2, b = [1,0] Output:
阅读全文
posted @ 2021-04-01 10:16
habibah_chang

浙公网安备 33010602011771号