随笔分类 - leetcode
摘要:三种方法: 1. 对每一个字符,从左右两边开始算 2. 动态规划 string input; int length = input.length(); int[][] r= new int[length][length]; for (int i = length - 1; i >= 0; i --)
阅读全文
摘要:这类问题可以先用递归思考,再反过来想出动态规划的方法。 10. Regular Expression Matching 32. Longest Valid Parentheses 44. Wildcard Matching 72. Edit Distance 97. Interleaving Str
阅读全文
摘要:121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitte
阅读全文
摘要:169. Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. Y
阅读全文
摘要:找到环的起点。 一快一慢相遇初,从头再走再相逢。
阅读全文
摘要:137. Single Number II Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should h
阅读全文
摘要:156. Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same pare
阅读全文
摘要:图论的常见题目有两类,一类是求两点间最短距离,另一类是拓扑排序,两种写起来都很烦。 求最短路径: 127. Word Ladder Given two words (beginWord and endWord), and a dictionary's word list, find the leng
阅读全文
摘要:12. Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. [leetcode] 12. Intege
阅读全文
摘要:94. Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree [1,null,2,3],
阅读全文
摘要:1. 普通的二分法查找查找等于target的数字 2. 还可以查找小于target的数字中最小的数字和大于target的数字中最大的数字 由于新的查找结果总是比旧的查找结果更接近于target,因此只需不停更新result 3. 查找最接近于target的数字 这种情况下,新的查找结果不一定比旧的查
阅读全文
摘要:71. Simplify Path Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c
阅读全文
摘要:动态规划属于技巧性比较强的题目,如果看到过原题的话,对解题很有帮助 55. Jump Game Given an array of non-negative integers, you are initially positioned at the first index of the array.
阅读全文
摘要:一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations that the number could represe
阅读全文
摘要:需要注意overflow,特别是Integer.MIN_VALUE这个数字。 需要掌握二分法。 不用除法的除法,分而治之的乘方 2. Add Two Numbers You are given two linked lists representing two non-negative number
阅读全文
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique pe
阅读全文
摘要:这道题目一直不会做,因为要考虑的corner case 太多。 1. divisor equals 0. 2. dividend equals 0. 3. Is the result negative? 4. when dividend equals Integer.MIN_VALUE and di
阅读全文
摘要:public class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); int length = nums.length; int rr = Integer.MAX_VALUE; int result = ...
阅读全文
摘要:如果某一个字母代表的数字大于上一个字母代表的数字小,那么加上这个数字,否则,减去两倍的前一个数字,然后加上这一位数字。
阅读全文
摘要:关于罗马数字: I: 1V: 5X: 10L: 50C: 100D: 500M: 1000字母可以重复,但不超过三次,当需要超过三次时,用与下一位的组合表示:I: 1, II: 2, III: 3, IV: 4C: 100, CC: 200, CCC: 300, CD: 400 提取每一位digit
阅读全文

浙公网安备 33010602011771号