
LeetCode
文章平均质量分 85
qq_27012963
这个作者很懒,什么都没留下…
展开
-
九章算法 - 三、划分型动态规划 512. 513. 108. 437.
512. Decode Ways有一个消息包含A-Z通过以下规则编码'A' -> 1'B' -> 2...'Z' -> 26现在给你一个加密过后的消息,问有几种解码的方式提示:首先合法输入f[0] = 1.遍历s从1到n-1。如果当前字符不等于0那么f[i]+=f[i-1],如果当前字符的前一个字符不为0,并且两者加起来是小于26的,那么结果还要加上法f...原创 2019-07-24 17:35:04 · 495 阅读 · 0 评论 -
String - 5. 6.重写 14. 17. 20. 22. 38. 58. 71.
5. Longest Palindromic Substring原创 2018-05-19 10:38:38 · 237 阅读 · 0 评论 -
Math - 67. 69. 168. 171. 172. Two pointers - 28. 125.
67. Add BinaryGiven two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100...原创 2018-05-18 10:25:06 · 188 阅读 · 0 评论 -
Math - 7. 8.未做 9. 12. 13. 29. 43. 50. 60.###
7. Reverse IntegerGiven a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321提示:原数除以10取余。检查有没有溢出。对于负数,注意C/C++ 采用向零取整的方式,又称为截断取整。答案:class Solution {public: int rev...原创 2018-05-11 09:49:30 · 170 阅读 · 0 评论 -
Array - 121. 122. 152. 153. 154. 162. 167. 169. 189.
121. Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one...原创 2018-05-04 09:39:09 · 163 阅读 · 0 评论 -
Linked List - 92. 109. 141. 142.143. 147. 148. 160.(138在HashTable已做)
92. Reverse Linked List IIReverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output...原创 2018-05-10 11:18:30 · 201 阅读 · 0 评论 -
Hash Table - 3. 36. 49. 94. 136. 138. 166.187重做(1.18在Array中做过)
3. Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length ...原创 2018-05-05 18:34:58 · 224 阅读 · 1 评论 -
Linked List - 2. 19. 21. 24. 61. 82. 83. 86.
2. Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two nu...原创 2018-05-09 12:42:25 · 362 阅读 · 0 评论 -
Array - 26. 27. 31不会 33. 34. 35. 39. 40.
26. Remove Duplicates from Sorted ArrayGiven a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for anoth...原创 2018-04-21 20:55:51 · 161 阅读 · 0 评论 -
Backtracking - 46. 47.有问题 77. 89. 131. Stack - 103. 144. 150. 155. 173
46. Permutations提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:提示:答案:...原创 2018-05-25 09:34:20 · 137 阅读 · 0 评论 -
String - 91. 93. 151. 165. Dynamic Programming - 70. 95. 96. 139. 198.
91. Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given a non-empty string containing only digits, d...原创 2018-05-21 11:39:14 · 175 阅读 · 0 评论 -
九章算法 - 二、序列型动态规划 515. 664. 516. 392. 534. 149. 150. 151. 393.
515. Paint House这里有n个房子在一列直线上,现在我们需要给房屋染色,分别有红色蓝色和绿色。每个房屋染不同的颜色费用也不同,你需要设计一种染色方案使得相邻的房屋颜色不同,并且费用最小,返回最小的费用。费用通过一个nx3的矩阵给出,比如cost[0][0]表示房屋0染红色的费用,cost[1][2]表示房屋1染绿色的费用。提示:f[i][j]为第i栋房子涂成j颜色所需的最...原创 2019-07-24 09:05:09 · 696 阅读 · 1 评论 -
九章算法 - 一、坐标型动态规划 115. 397. 110. 553.
115.Unique Path II"不同的路径" 的跟进问题:现在考虑网格中有障碍物,那样将会有多少条不同的路径?网格中的障碍和空位置分别用 1 和 0 来表示。提示:注意初始化与前面不同,只能初始化第一个点。遍历f[m][n],一旦有障碍就设置为0,有左面或前面就+=。答案:class Solution {public: /** * @param ...原创 2019-07-22 10:51:25 · 356 阅读 · 0 评论 -
九章算法 - 零、动态规划入门 669. 114. 116.
669.Coin Change给出不同面额的硬币以及一个总金额. 写一个方法来计算给出的总金额可以换取的最少的硬币数量. 如果已有硬币的任意组合均无法与总金额面额相等, 那么返回-1提示:最后一步为最优策略中使用的最后一枚硬币,子问题为最少硬币拼出更小的面值27-ak。 转移方程f[X] = min{f[X-2]+1, f[X-5]+1, f[X-7]+1}...原创 2019-07-22 10:20:01 · 251 阅读 · 0 评论 -
九章算法 - 五、背包型动态规划 92. 563. 564. 125. 440.
关键点:最后一个背包的内的物品是哪个,最后一个物品有没有进背包。 背包问题要将总承重放入状态。可行性背包,计数型背包,最值型背包。92. Backpack在n个物品中挑选若干物品装入背包,最多能装多满?假设背包的大小为m,每个物品的大小为A[i]提示: 两种思路,第一种状态是f[i][w]表示能否用前i个物品拼出重量w。优化空间的的话,可以不在f中记...原创 2019-07-25 15:23:08 · 481 阅读 · 0 评论 -
九章算法 - 四、博弈型动态规划 394.
394. Coins in a Line提示: 可以证明, 当硬币数目是3的倍数的时候, 先手玩家必败, 否则他必胜. 当硬币数目是3的倍数时, 每一轮先手者拿a个, 后手者拿3-a个即可, 后手必胜. 若不是3的倍数, 先手者可以拿1或2个, 此时剩余硬币个数就变成了3的倍数. 如果用动态规划的方法,在当下局面...原创 2019-07-25 10:04:29 · 632 阅读 · 0 评论 -
剑指offer —— 第4章解决面试题的思路 面试题 19 - 28
19.二叉树的镜像操作给定的二叉树,将其变换为源二叉树的镜像。二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 7 5思...原创 2018-09-07 09:26:28 · 130 阅读 · 0 评论 -
剑指offer —— 第3章高质量的代码 面试题 11 - 18
11.数值的整数次方给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。思路:首先处理指数为正数的情况,然后如果指数为负且底数不为0,结果取倒数。注意double类型相等的比较。class Solution { public: bool g_InvalidInput = false; double P...原创 2018-08-16 10:32:48 · 231 阅读 · 0 评论 -
剑指offer —— 第2章面试需要的基础知识 面试题 3 - 10
3.二维数组中的查找在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。思路:从右上角开始,不断缩小行数或者列数class Solution {public: bool Find(int target, vector<vector...原创 2018-07-18 16:06:44 · 220 阅读 · 0 评论 -
Array - 41. 42. 55. 45. 48. 53. 54. 59. 56. 57.
41. First Missing Positive Given an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0]Output: 3提示:通过for while swap将每个正数放到正确的位置,然后for循环return第一个不正确数的位置,都正确retu...原创 2018-04-23 12:37:09 · 933 阅读 · 0 评论 -
Array - 81. 88. 90. 105. 106. 118. 119. 120.
81. Search in Rotated Sorted Array IISuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).You are given a ...原创 2018-05-03 12:21:20 · 173 阅读 · 0 评论 -
Array - 1. 11. 15. 16. 18.
1. Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use t...原创 2018-04-21 18:01:30 · 207 阅读 · 0 评论 -
Array - 62. 63. 64. 66. 73. 74. 75. 78. 79. 80
62. Unique PathsA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying t...原创 2018-04-24 18:53:34 · 199 阅读 · 0 评论