2018年4月14日

350 Intersection of Two Arrays II 两个数组的交集 II

摘要: 给定两个数组,写一个方法来计算它们的交集。例如:给定 nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回 [2, 2].注意: 输出结果中每个元素出现的次数,应与元素在两个数组中出现的次数一致。 我们可以不考虑输出结果的顺序。跟进: 如果给定的数组已经排好序呢?你将如何 阅读全文

posted @ 2018-04-14 23:24 lina2014 阅读(165) 评论(0) 推荐(0)

349 Intersection of Two Arrays 两个数组的交集

摘要: 给定两个数组,写一个函数来计算它们的交集。例子: 给定 num1= [1, 2, 2, 1], nums2 = [2, 2], 返回 [2].提示: 每个在结果中的元素必定是唯一的。 我们可以不考虑输出结果的顺序。详见:https://leetcode.com/problems/intersecti 阅读全文

posted @ 2018-04-14 23:15 lina2014 阅读(156) 评论(0) 推荐(0)

347 Top K Frequent Elements 前K个高频元素

摘要: 给定一个非空的整数数组,返回其中出现频率前 k 高的元素。例如,给定数组 [1,1,1,2,2,3] , 和 k = 2,返回 [1,2]。注意: 你可以假设给定的 k 总是合理的,1 ≤ k ≤ 数组中不相同的元素的个数。 你的算法的时间复杂度必须优于 O(n log n) , n 是数组的大小。 阅读全文

posted @ 2018-04-14 23:09 lina2014 阅读(187) 评论(0) 推荐(0)

345 Reverse Vowels of a String 反转字符串中的元音字母

摘要: 编写一个函数,以字符串作为输入,反转该字符串中的元音字母。示例 1:给定 s = "hello", 返回 "holle".示例 2:给定 s = "leetcode", 返回 "leotcede".注意:元音字母不包括 "y".详见:https://leetcode.com/problems/rev 阅读全文

posted @ 2018-04-14 22:58 lina2014 阅读(221) 评论(0) 推荐(0)

344 Reverse String 反转字符串

摘要: 请编写一个函数,其功能是将输入的字符串反转过来。示例:输入:s = "hello"返回:"olleh"详见:https://leetcode.com/problems/reverse-string/description/C++: 阅读全文

posted @ 2018-04-14 22:53 lina2014 阅读(154) 评论(0) 推荐(0)

343 Integer Break 整数拆分

摘要: 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。例如,给定 n = 2,返回1(2 = 1 + 1);给定 n = 10,返回36(10 = 3 + 3 + 4)。注意:你可以假设 n 不小于2且不大于58。 详见:https://leetco 阅读全文

posted @ 2018-04-14 22:46 lina2014 阅读(210) 评论(0) 推荐(0)

342 Power of Four 4的幂

摘要: 给定一个整数 (32位有符整数型),请写出一个函数来检验它是否是4的幂。示例:当 num = 16 时 ,返回 true 。 当 num = 5时,返回 false。问题进阶:你能不使用循环/递归来解决这个问题吗? 详见:https://leetcode.com/problems/power-of- 阅读全文

posted @ 2018-04-14 22:37 lina2014 阅读(102) 评论(0) 推荐(0)

338 Counting Bits Bit位计数

摘要: 给定一个非负整数 num。 对于范围 0 ≤ i ≤ num 中的每个数字 i ,计算其二进制数中的1的数目并将它们作为数组返回。示例:比如给定 num = 5 ,应该返回 [0,1,1,2,1,2].进阶: 给出时间复杂度为O(n * sizeof(integer)) 的解答非常容易。 但是你可以 阅读全文

posted @ 2018-04-14 22:13 lina2014 阅读(158) 评论(0) 推荐(0)

337 House Robber III 打家劫舍 III

摘要: 小偷又发现一个新的可行窃的地点。 这个地区只有一个入口,称为“根”。 除了根部之外,每栋房子有且只有一个父房子。 一番侦察之后,聪明的小偷意识到“这个地方的所有房屋形成了一棵二叉树”。 如果两个直接相连的房子在同一天晚上被打劫,房屋将自动报警。在不触动警报的情况下,计算小偷一晚能盗取的最高金额。示例 阅读全文

posted @ 2018-04-14 22:03 lina2014 阅读(140) 评论(0) 推荐(0)

336 Palindrome Pairs 回文对

摘要: 给定一组独特的单词, 找出在给定列表中不同 的索引对(i, j),使得关联的两个单词,例如:words[i] + words[j]形成回文。示例 1:给定 words = ["bat", "tab", "cat"]返回 [[0, 1], [1, 0]]回文是 ["battab", "tabbat"] 阅读全文

posted @ 2018-04-14 21:32 lina2014 阅读(118) 评论(0) 推荐(0)

334 Increasing Triplet Subsequence 递增的三元子序列

摘要: 给定一个未排序的数组,请判断这个数组中是否存在长度为3的递增的子序列。正式的数学表达如下: 如果存在这样的 i, j, k, 且满足 0 ≤ i < j < k ≤ n-1, 使得 arr[i] < arr[j] < arr[k] ,返回 true ; 否则返回 false 。要求算法时间复杂度为O 阅读全文

posted @ 2018-04-14 20:01 lina2014 阅读(140) 评论(0) 推荐(0)

332 Reconstruct Itinerary 重建行程单

摘要: Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tick 阅读全文

posted @ 2018-04-14 19:37 lina2014 阅读(125) 评论(0) 推荐(0)

331 Verify Preorder Serialization of a Binary Tree 验证二叉树的前序序列化

摘要: 序列化二叉树的一种方法是使用前序遍历。当我们遇到一个非空节点时,我们可以记录这个节点的值。如果它是一个空节点,我们可以使用一个标记值,例如 #。 _9_ / \ 3 2 / \ / \ 4 1 # 6/ \ / \ / \# # # # # #例如,上面的二叉树可以被序列化为字符串"9,3,4,#, 阅读全文

posted @ 2018-04-14 17:46 lina2014 阅读(177) 评论(0) 推荐(0)

330 Patching Array

摘要: Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be for 阅读全文

posted @ 2018-04-14 17:37 lina2014 阅读(83) 评论(0) 推荐(0)

329 Longest Increasing Path in a Matrix 矩阵中的最长递增路径

摘要: Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or dow 阅读全文

posted @ 2018-04-14 17:22 lina2014 阅读(195) 评论(0) 推荐(0)

328 Odd Even Linked List 奇偶链表

摘要: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文

posted @ 2018-04-14 17:07 lina2014 阅读(147) 评论(0) 推荐(0)

327 Count of Range Sum 区间和计数

摘要: Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the eleme 阅读全文

posted @ 2018-04-14 16:54 lina2014 阅读(165) 评论(0) 推荐(0)

326 Power of Three 3的幂

摘要: 给出一个整数,写一个函数来确定这个数是不是3的一个幂。后续挑战:你能不使用循环或者递归完成本题吗? 详见:https://leetcode.com/problems/power-of-three/description/ C++: 方法一: 方法二: 参考:https://www.cnblogs.c 阅读全文

posted @ 2018-04-14 16:36 lina2014 阅读(126) 评论(0) 推荐(0)

324 Wiggle Sort II 摆动排序 II

摘要: 给定一个无序的数组nums,将它重新排列成nums[0] < nums[1] > nums[2] < nums[3]...的顺序。例子:(1) 给定nums = [1, 5, 1, 1, 6, 4],一个可能的结果是[1, 4, 1, 5, 1, 6]。(2) 给定nums = [1, 3, 2, 阅读全文

posted @ 2018-04-14 16:29 lina2014 阅读(287) 评论(0) 推荐(0)

322 Coin Change 零钱兑换

摘要: 给定不同面额的硬币(coins)和一个总金额(amount)。写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合方式能组成总金额,返回-1。示例 1:coins = [1, 2, 5], amount = 11return 3 (11 = 5 + 5 + 1)示例 2:co 阅读全文

posted @ 2018-04-14 16:16 lina2014 阅读(417) 评论(0) 推荐(0)

321 Create Maximum Number 拼接最大数

摘要: 已知长度分别为 m 和 n 的两个数组,其元素由 0-9 构成,直观地表示两个自然数各位上的数字。现在从这两个数组中选出 k (k <= m + n) 个数字拼接成一个新的数,要求从同一个数组中取出的数字保持其在原数组中的相对顺序。求满足该条件的最大数。结果返回一个表示该最大数的长度为k的数组。尽可 阅读全文

posted @ 2018-04-14 16:07 lina2014 阅读(463) 评论(0) 推荐(0)

319 Bulb Switcher 灯泡开关

摘要: 初始时有 n 个灯泡关闭。 第 1 轮,你打开所有的灯泡。 第 2 轮,每两个灯泡切换一次开关。 第 3 轮,每三个灯泡切换一次开关(如果关闭,则打开,如果打开则关闭)。对于第 i 轮,你每 i 个灯泡切换一次开关。 对于第 n 轮,你只切换最后一个灯泡的开关。 找出 n 轮后有多少个亮着的灯泡。示 阅读全文

posted @ 2018-04-14 15:42 lina2014 阅读(179) 评论(0) 推荐(0)

318 Maximum Product of Word Lengths 最大单词长度乘积

摘要: 给定一个字符串数组words,找到length(word[i]) * length(word[j])的最大值,并且两个单词不含公共的字母。你可以认为每个单词只包含小写字母。如果不存在这样的两个单词,返回 0。示例 1:输入 ["abcw", "baz", "foo", "bar", "xtfn", 阅读全文

posted @ 2018-04-14 15:31 lina2014 阅读(157) 评论(0) 推荐(0)

316 Remove Duplicate Letters 去除重复字母

摘要: 给定一个仅包含小写字母的字符串,去除重复的字母使得所有字母出现且仅出现一次。你必须保证返回结果是所有可能结果中的以字典排序的最短结果。例如:给定 "bcabc"返回 "abc"给定 "cbacdcbc"返回 "acdb" 详见:https://leetcode.com/problems/remove 阅读全文

posted @ 2018-04-14 15:05 lina2014 阅读(169) 评论(0) 推荐(0)

315 Count of Smaller Numbers After Self 计算右侧小于当前元素的个数

摘要: 给定一个整型数组 nums,按要求返回一个新的 counts 数组。数组 counts 有该性质: counts[i] 的值是 nums[i] 右侧小于nums[i] 的元素的数量。例子:给定 nums = [5, 2, 6, 1]5的右侧有2个更小的元素 (2 和 1).2的右侧仅有1个更小的元素 阅读全文

posted @ 2018-04-14 13:28 lina2014 阅读(618) 评论(0) 推荐(0)

313 Super Ugly Number 超级丑数

摘要: 编写一段程序来寻找第 n 个超级丑数。超级丑数是指其所有质因数都在长度为k的质数列表primes中的正整数。例如,[1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32],是给定长度为 4 的质数列表primes = [2, 7, 13, 19]的前 12 个超级丑数。 阅读全文

posted @ 2018-04-14 13:06 lina2014 阅读(170) 评论(0) 推荐(0)

312 Burst Balloons 戳气球

摘要: 现有 n 个气球按顺序排成一排,每个气球上标有一个数字,这些数字用数组 nums 表示。现在要求你戳破所有的气球。每当你戳破一个气球 i 时,你可以获得 nums[left] * nums[i] * nums[right] 个硬币。 这里的 left 和 right 代表和 i 相邻的气球的序号。 阅读全文

posted @ 2018-04-14 12:51 lina2014 阅读(285) 评论(0) 推荐(0)

309 Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期

摘要: Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complet 阅读全文

posted @ 2018-04-14 12:17 lina2014 阅读(138) 评论(0) 推荐(0)

307 Range Sum Query - Mutable

摘要: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by upda 阅读全文

posted @ 2018-04-14 12:00 lina2014 阅读(124) 评论(0) 推荐(0)

306 Additive Number 加法数

摘要: Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the fi 阅读全文

posted @ 2018-04-14 11:34 lina2014 阅读(133) 评论(0) 推荐(0)

304 Range Sum Query 2D - Immutable 二维区域和检索 - 不可变

摘要: 给定一个二维矩阵,计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2)。 上图子矩阵左上角 (row1, col1) = (2, 1) ,右下角(row2, col2) = (4, 3),该子矩形内元素的总和为8。示例:给定 matrix 阅读全文

posted @ 2018-04-14 10:49 lina2014 阅读(194) 评论(0) 推荐(0)

303 Range Sum Query - Immutable 区域和检索 - 不可变

摘要: 给定一个数组,求出数组从索引 i 到 j (i ≤ j) 范围内元素的总和,包含 i, j 两点。例如:给定nums = [-2, 0, 3, -5, 2, -1],求和函数为sumRange()sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5 阅读全文

posted @ 2018-04-14 10:47 lina2014 阅读(205) 评论(0) 推荐(0)

导航