
LeetCode
KarmenChan
Coding
展开
-
LeetCode | 63. Unique Paths II
63. Unique Paths IIDescription描述:https://leetcode.com/problems/unique-paths-ii/description/题意:m列 × n行 的有障碍物的网格,从左上角第一个到右下角最后一个(只能往右和下这两个方向走),有多少条不重复的路径Solution: (Java)class Solution { public ...原创 2020-01-17 16:48:59 · 134 阅读 · 0 评论 -
LeetCode | # 62. Unique Paths
62. Unique PathsDescription描述:https://leetcode.com/problems/unique-paths/description/题意:m列 × n行 的网格,从左上角第一个到右下角最后一个(只能往右和下这两个方向走),有多少条不重复的路径Solution 1: (Java) 超时class Solution { public int pa...原创 2020-01-16 17:14:50 · 181 阅读 · 0 评论 -
LeetCode | 61. Rotate List
61. Rotate ListDescription描述:https://leetcode.com/problems/rotate-list/description/题意:对于给定链表,向右旋转k个位置。Solution: (Java)/** * Definition for singly-linked list. * public class ListNode { * i...原创 2020-01-13 16:17:51 · 136 阅读 · 0 评论 -
LeetCode | # 60. Permutation Sequence
60. Permutation SequenceDescription描述:https://leetcode.com/problems/permutation-sequence/description/题意:给定1~n这n个数,返回第k个排列。Solution: (Java)class Solution { public String getPermutation(int n, ...原创 2020-01-10 22:18:41 · 171 阅读 · 0 评论 -
LeetCode | 59. Spiral Matrix II
59. Spiral Matrix IIDescription描述:https://leetcode.com/problems/spiral-matrix-ii/description/题意:给定整数n,按螺旋顺序填充n×n(从1~n^2)的二维矩阵。Solution: (Java)class Solution { public int[][] generateMatrix(in...原创 2019-12-31 14:21:54 · 169 阅读 · 0 评论 -
LeetCode | 58. Length of Last Word
58. Length of Last WordDescription描述:https://leetcode.com/problems/length-of-last-word/description/题意:返回字符串中最后一个单词的长度Solution: (Java)class Solution { public int lengthOfLastWord(String s) { ...原创 2019-12-31 13:52:13 · 165 阅读 · 0 评论 -
LeetCode | # 56. Merge Intervals
56. Merge IntervalsDescription描述:https://leetcode.com/problems/merge-intervals/description/题意:给定一组区间,合并重叠的区间。Solution: (Java)class Solution { private class IntervalComparator implements Compa...原创 2019-12-27 22:43:42 · 190 阅读 · 0 评论 -
LeetCode | # 45. Jump Game II
45. Jump Game IIDescription描述:https://leetcode.com/problems/jump-game-ii/description/题意:给定一维数组,数组中的值表示该位置能往后跳的最大位置,求达到最后一个位置需要跳的最小步数。Solution: (Java)class Solution { public int jump(int[] num...原创 2019-12-22 13:37:19 · 150 阅读 · 0 评论 -
LeetCode | # 55. Jump Game
55. Jump GameDescription描述:https://leetcode.com/problems/jump-game/description/题意:给定一维数组,数组中的值表示该位置能往后跳的最大位置,求是否能到达数组的最后一个位置。Solution: (Java)class Solution { public boolean canJump(int[] nums...原创 2019-12-05 16:34:36 · 152 阅读 · 0 评论 -
LeetCode | 54. Spiral Matrix
54. Spiral MatrixDescription描述:https://leetcode.com/problems/spiral-matrix/description/题意:将一个数据按照螺旋状进行遍历。Solution: (Java)class Solution { public List<Integer> spiralOrder(int[][] matrix...原创 2019-11-30 16:46:48 · 157 阅读 · 0 评论 -
LeetCode | # 53. Maximum Subarray
53. Maximum SubarrayDescription描述:https://leetcode.com/problems/maximum-subarray/description/题意:找出数组中和最大的子数组。Solution 1: (Java)class Solution { public int maxSubArray(int[] nums) { in...原创 2019-11-29 22:40:57 · 163 阅读 · 0 评论 -
LeetCode | # 50. Pow(x, n)
50. Pow(x, n)Description描述:https://leetcode.com/problems/powx-n/description/题意:求 x 的 n 次方。Solution: (Java)class Solution { public double myPow(double x, int n) { if (n == 0) ...原创 2019-11-20 16:44:39 · 138 阅读 · 0 评论 -
LeetCode | # 49. Group Anagrams
49. Group AnagramsDescription描述:https://leetcode.com/problems/group-anagrams/description/题意:将字符串按照组成的字母相同进行分类。Solution: (Java)class Solution { public List<List<String>> groupAnagr...原创 2019-11-19 22:56:01 · 190 阅读 · 0 评论 -
LeetCode | 48. Rotate Image
48. Rotate ImageDescription描述:https://leetcode.com/problems/rotate-image/description/题意:将一个矩阵(二维数组)顺时针旋转90度,不能分配额外的二维空间。Solution: (Java)class Solution { public void rotate(int[][] matrix) { ...原创 2019-11-18 19:36:08 · 129 阅读 · 0 评论 -
LeetCode | 47. Permutations II
47. Permutations IIDescription描述:https://leetcode.com/problems/permutations-ii/description/题意:返回一个数组(数组中可能有重复)中所有的唯一的全排列。Solution: (Java)class Solution { List<List<Integer>> resul...原创 2019-11-12 21:25:13 · 143 阅读 · 0 评论 -
LeetCode | 46. Permutations
46. PermutationsDescription描述:https://leetcode.com/problems/permutations/description/题意:返回一个数组的全排列Solution: (Java)class Solution { List<List<Integer>> result = new ArrayList<&g...原创 2019-11-12 20:38:22 · 132 阅读 · 0 评论 -
LeetCode | # 43. Multiply Strings
43. Multiply StringsDescription描述:https://leetcode.com/problems/multiply-strings/description/题意:将字符串表示的两个数相乘计算结果,不可调用大整数包或直接转为整数相乘。Solution 1: (Java)class Solution { public String multiply(St...原创 2019-11-09 20:08:30 · 203 阅读 · 0 评论 -
LeetCode | 40. Combination Sum II
40. Combination Sum IIDescription描述:https://leetcode.com/problems/combination-sum-ii/description/题意:从给定数组中找出所有可能的组合(一个数只能取一次,数组中有重复的数),使得组合的和等于目标值。Solution: (Java)class Solution { List<Lis...原创 2019-11-09 16:01:22 · 173 阅读 · 0 评论 -
LeetCode | 39. Combination Sum
39. Combination SumDescription描述:https://leetcode.com/problems/combination-sum/description/题意:从给定数组中找出所有可能的组合(一个数可以取多次),使得组合的和等于目标值。Solution: (Java)class Solution { List<List<Integer>...原创 2019-11-08 15:30:29 · 154 阅读 · 0 评论 -
LeetCode | # 37. Sudoku Solver
37. Sudoku SolverDescription描述:https://leetcode.com/problems/sudoku-solver/description/题意:求解数独(9×9)Solution 1: (Java)class Solution { ArrayList<ArrayList<Character>> row = new Arr...原创 2019-11-07 20:26:18 · 219 阅读 · 0 评论 -
LeetCode | 38. Count and Say
38. Count and SayDescription描述:https://leetcode.com/problems/count-and-say/description/题意:从1开始,从左至右,对数字计数,将个数和对应的数字连接(计数并读出)并作为下一个数。Solution: (Java)class Solution { public String countAndSay(...原创 2019-11-05 15:04:05 · 172 阅读 · 0 评论 -
LeetCode | 35. Search Insert Position
35. Search Insert PositionDescription描述:https://leetcode.com/problems/search-insert-position/description/题意:在有序数组中查找目标,不存在则返回插入的下标。Solution: (Java)class Solution { public int searchInsert(int...原创 2019-11-04 21:58:49 · 194 阅读 · 0 评论 -
LeetCode | 36. Valid Sudoku
36. Valid SudokuDescription描述:https://leetcode.com/problems/valid-sudoku/description/题意:检查数独(未解答之前)是否有效Solution: (Java)class Solution { public boolean isValidSudoku(char[][] board) { ...原创 2019-11-04 19:43:28 · 162 阅读 · 0 评论 -
LeetCode | 34. Find First and Last Position of Element in Sorted Array
34. Find First and Last Position of Element in Sorted ArrayDescription描述:https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/description/题意:在有序数组中,查找目标数的第一次和最后一次出现...原创 2019-11-01 13:32:05 · 113 阅读 · 0 评论 -
LeetCode | # 33. Search in Rotated Sorted Array
33. Search in Rotated Sorted ArrayDescription描述:https://leetcode.com/problems/search-in-rotated-sorted-array/description/题意:在旋转有序数组中,查找指定的数,时间复杂度要求O(log n)。Solution: (Java)class Solution { pu...原创 2019-10-31 17:50:30 · 228 阅读 · 0 评论 -
LeetCode | # 31. Next Permutation
31. Next PermutationDescriptionImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rear...原创 2019-10-30 21:02:30 · 142 阅读 · 0 评论 -
LeetCode | # 29. Divide Two Integers
29. Divide Two IntegersDescription描述:https://leetcode.com/problems/divide-two-integers/description/Solution: (Java)class Solution { public int divide(int dividend, int divisor) { if (d...原创 2019-10-30 17:01:51 · 130 阅读 · 0 评论 -
LeetCode | Container With Most Water
11. Container With Most WaterDescriptionGiven n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints o...原创 2019-05-18 12:05:27 · 107 阅读 · 0 评论 -
LeetCode | Longest Common Prefix
14. Longest Common PrefixDescriptionWrite a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input...原创 2019-05-22 13:23:22 · 108 阅读 · 0 评论 -
LeetCode | Roman to Integer
13. Roman to IntegerDescriptionRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 5...原创 2019-05-21 17:38:08 · 172 阅读 · 0 评论 -
LeetCode | Palindrome Number
9.Palindrome NumberDescriptionDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Inp...原创 2019-05-15 19:22:33 · 143 阅读 · 0 评论 -
LeetCode | Integer to Roman
12. Integer to RomanDescriptionRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 5...原创 2019-05-20 14:41:07 · 110 阅读 · 0 评论 -
LeetCode | String to Integer (atoi)
DescriptionImplement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found.Then, start...原创 2019-05-14 21:28:32 · 107 阅读 · 0 评论 -
LeetCode | Reverse Integer
7.Reverse IntegerDescriptionGiven a 32-bit signed integer, reverse digits of an integer.ExampleExample 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output:...原创 2019-05-09 21:31:42 · 131 阅读 · 0 评论 -
LeetCode | ZigZag Conversion
6.ZigZag ConversionDescriptionThe string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibil...原创 2019-05-06 22:38:07 · 122 阅读 · 0 评论 -
LeetCode | Longest Palindromic Substring
5.Longest Palindromic SubstringDescriptionGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.ExampleInput: "babad"Output: "bab"Not...原创 2019-04-29 22:43:12 · 106 阅读 · 0 评论 -
LeetCode | Longest Substring Without Repeating Characters
3.Longest Substring Without Repeating CharactersDescription:Given a string, find the length of the longest substring without repeating characters.Example:Input: "abcabcbb"Output: 3 Explanation: ...原创 2018-09-20 15:12:48 · 112 阅读 · 0 评论 -
LeetCode | Two Sum
1.Two SumDescription:Given 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...原创 2018-09-19 16:51:25 · 138 阅读 · 0 评论 -
LeetCode | 3Sum
15. 3SumDescriptionGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solut...原创 2019-05-28 11:35:10 · 117 阅读 · 0 评论 -
LeetCode | 4Sum
18. 4SumDescriptionGiven an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array whic...原创 2019-06-06 15:42:11 · 106 阅读 · 0 评论