- 博客(44)
- 收藏
- 关注
原创 Leetcode1-100: 44. Wildcard Matching
Leetcode1-100: 44. Wildcard Matching问题描述解题思路implement 1implement 2implement 3代码实现implement 1implement 2implement 3问题描述题目要求: 实现text和pattern的匹配功能,输出true和false解题思路这一题跟第10题(Regular Expression Matching)很像,但是加上了'?',去掉了'.'跟那一题很像,不过用backtrack的话一直通不过说超时,暂时只用了
2020-06-17 14:12:00 196
原创 Leetcode1-100: 43. Multiply Strings
Leetcode1-100: 43. Multiply Strings问题描述解题思路代码实现分析后记问题描述Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"Example
2020-06-17 13:17:52 154
原创 Leetcode1-100: 42. Trapping Rain Water
Leetcode1-100: 42. Trapping Rain Water问题描述解题思路1. 统计横向的格子数量2. 统计每一列的储水量3. 利用动态规划来改进思路2代码实现implement 1implement 2implement 3分析后记问题描述Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is a
2020-06-17 13:04:38 200
原创 Leetcode1-100: 41. First Missing Positive
Leetcode1-100: 41. First Missing Positive问题描述解题思路implement 1implement 2代码实现implement 1implement 2分析后记问题描述题目要求: 输入一个整形数组,输出里面缺失的最小的正整数。解题思路由于题目中要求了时间复杂度是O(n),还要求空间复杂度是常数,所以这题变得难度大了很多。但是首先分析一下如果去掉这些要求,可以用一个额外的数组来作为flag表示状态的话,这题就简单了很多,注意:假设数组有n个元素,那么最后的结
2020-06-09 08:32:39 186
原创 Leetcode1-100: 40. Combination Sum II
Leetcode1-100: 40. Combination Sum II问题描述解题思路代码实现问题描述**题目要求:**见上一题解题思路跟上一题的思路基本一样,只不过这题的条件变成每个元素只能出现一次了,只需要微调上一题的解法即可。代码实现 public List<List<Integer>> combinationSum2(int[] candidates, int target) { List<List<Integer>>
2020-06-09 07:40:43 182
原创 Leetcode1-100: 39. Combination Sum
Leetcode1-100: 39. Combination Sum问题描述解题思路代码实现问题描述题目要求: 输入一个正整数型的数组和一个正整数target,找出用数组中元素组成的所有组合,使得组合的和等于target。注意,数组中元素可以重复使用解题思路很经典的递归题目,每次使用需要记录一些辅助的值,所以重新写一个backtrack函数用来辅助操作。传入的参数是当前需要检验的集合,数组中使用的数据开始位置start以及target的余额,每次检查到当前的target为0时说明当前的待检验集合是
2020-06-09 07:32:40 182
原创 Leetcode1-100: 38. Count and Say
Leetcode1-100: 38. Count and Say问题描述解题思路代码实现问题描述题目要求: 输入一个数字,输出这个数字代表的count-and-say字符串,注意每个数字对应的字符串需要根据上一个数字的字符串来得出(例如4对应的是1211,就是1个1,1个2,2个1,所以5对应的字符串就是111221)解题思路比较简单,直接brute force,迭代从1往后解,每次把上一个的结果最后下一个的输入来做即可。代码实现public String countAndSay(int n)
2020-06-07 06:58:02 201
原创 Leetcode1-100: 37. Sudoku Solver
Leetcode1-100: 37. Sudoku Solver问题描述解题思路代码实现问题描述题目要求: 跟上一题差不多,输入一个代表数独的字符二维数组,找出这个数独的正确解。解题思路这题时很经典的数独的回溯解法,对于数独中的元素来说,每次输入一个可能解,一个一个试如果错误就排除这个答案然后直到找到最后的解为止。注意这里每次输入一个可能解之后可以用上一题的代码来检查一下结果。所以直接粘贴了上一题的代码作为一个函数。代码实现public void solveSudoku(char[][] bo
2020-06-07 06:52:46 166
原创 Leetcode1-100: 36. Valid Sudoku
Leetcode1-100: 36. Valid Sudoku问题描述解题思路implement 1implement 2代码实现implement 1 HashSet法implement 2 Brute Force法问题描述题目要求: 输入一个代表数独的字符型二维数组,里面元素是’.'说明没有填上,判断这个数组代表的数独是否是合法状态。解题思路implement 1使用一个字符型hashSet,每次遇到一个非`'.'`元素c就存储一个字符串格式为:C + in Line + lineNo.
2020-06-07 06:39:34 144
原创 Leetcode1-100: 35. Search Insert Position
Leetcode1-100: 35. Search Insert Position问题描述解题思路代码实现问题描述题目要求: 输入一个有序数组和一个待插入的值,输出插入的位置使得插入后的数组仍然是有序的解题思路这题很简单,直接从前往后找就可以。代码实现public int searchInsert(int[] nums, int target) { for(int i = 0; i < nums.length; i++) if(nums[i] &
2020-06-05 03:41:24 157
原创 Leetcode1-100: 34. Find First and Last Position of Element in Sorted Array
Leetcode1-100: 34. Find First and Last Position of Element in Sorted Array问题描述解题思路代码实现问题描述题目要求: 输入一个有序的数组,输出target出现的第一个和最后一个位置,如果没有出现过就输出[-1, -1]解题思路跟上一题很相似, 这次也是分两次分别找出start和end,第一次找start的时候,查询到target值后看midpoint前面是否还有等于target的值,如果有的话不跳出循环,而是当作没找到设置r
2020-06-05 03:38:36 135
原创 Leetcode1-100: 33. Search in Rotated Sorted Array
Leetcode1-100: 33. Search in Rotated Sorted Array问题描述解题思路代码实现后记问题描述题目要求: 给定一个有序的数组,已知这个数组在某个位置进行了扭转,(即[0,1,2,3,4,5] --> [3,4,5,0,1,2]类似操作),要求在logn时间内,找到给定的target对应的位置index解题思路首先找到pivot的位置,即找到数组中发生扭转的位置(即例子中0的位置index 3),有序题目要求是logn时间内完成,所以这个查找肯定是要用b
2020-06-05 03:31:45 160
原创 Leetcode1-100: 32. Longest Valid Parentheses
Leetcode1-100: 32. Longest Valid Parentheses问题描述解题思路代码实现问题描述Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest va
2020-05-30 14:56:42 143
原创 Leetcode1-100: 31. Next Permutation
Leetcode1-100: 31. Next Permutation问题描述解题思路代码实现问题描述Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order
2020-05-30 14:43:45 141
原创 Leetcode1-100: 30. Substring with Concatenation of All Words
Leetcode1-100: 30. Substring with Concatenation of All Words问题描述解题思路代码实现implement 1 brute forceimplement 2 sliding window分析问题描述You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(
2020-05-30 14:27:40 183
原创 Leetcode1-100: 29. Divide Two Integers
Leetcode1-100: 29. Divide Two Integers问题描述解题思路代码实现 错误实现 正确实现分析问题描述Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient afte
2020-05-28 07:32:26 161
原创 Leetcode1-100: 28. Implement strStr()
@[TOC](Leetcode1-100: 28. Implement strStr())问题描述Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:Input:
2020-05-26 12:42:22 146
原创 Leetcode1-100: 27. Remove Element
Leetcode1-100: 27. Remove Element问题描述解题思路代码实现问题描述Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-p
2020-05-26 12:35:58 166
原创 Leetcode1-100: 26. Remove Duplicates from Sorted Array
Leetcode1-100: 26. Remove Duplicates from Sorted Array问题描述解题思路代码实现问题描述Given 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 another array, you must do
2020-05-26 12:31:16 159
原创 Leetcode1-100: 25. Reverse Nodes in k-Group
Leetcode1-100: 25. Reverse Nodes in k-Group问题描述解题思路代码实现分析问题描述Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the numb
2020-05-26 05:24:21 138
原创 Leetcode1-100: 24. Swap Nodes in Pairs
Leetcode1-100: 24. Swap Nodes in Pairs问题描述解题思路代码实现分析问题描述Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s nodes, only nodes itself may be changed.Example:Given 1->2->3->4, you s
2020-05-26 05:06:53 122
原创 Leetcode1-100: 23. Merge k Sorted Lists
Leetcode1-100: 23. Merge k Sorted Lists问题描述解题思路代码实现implement 1 Brute forceimplement 2 Priority Queueimplement 3. Divide and conquer分析问题描述Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[
2020-05-26 05:00:23 135
原创 Leetcode1-100: 22. Generate Parentheses
Leetcode1-100: 22. Generate Parentheses问题描述解题思路代码实现implement 1 Brute forceimplement 2 回溯法implement 3 拆分法复杂度分析分析问题描述Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solutio
2020-05-26 04:31:04 158
原创 Leetcode1-100: 21. Merge Two Sorted Lists
Leetcode1-100: 21. Merge Two Sorted Lists问题描述解题思路代码实现复杂度分析分析问题描述Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Out
2020-05-21 13:22:16 185
原创 Leetcode1-100: 20. Valid Parentheses
Leetcode1-100: 20. Valid Parentheses问题描述解题思路代码实现复杂度分析分析问题描述Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type o
2020-05-21 13:14:01 131
原创 Leetcode1-100: 19. Remove Nth Node From End of List
Leetcode1-100: 19. Remove Nth Node From End of List问题描述解题思路代码实现复杂度分析分析问题描述Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node
2020-05-19 13:49:10 110
原创 Leetcode1-100: 18. 4Sum
Leetcode1-100: 18. 4Sum问题描述解题思路代码实现复杂度分析分析问题描述Given 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 which gives the sum of target.Not
2020-05-19 13:34:48 128
原创 Leetcode1-100: 17. Letter Combinations of a Phone Number
Leetcode1-100: 17. Letter Combinations of a Phone Number问题描述解题思路代码实现implement 1. Brute forceimplement 2. 递归法复杂度分析分析问题描述Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mappin
2020-05-19 13:17:48 227
原创 Leetcode1-100: 16. 3Sum Closest
Leetcode1-100: 16. 3Sum Closest问题描述解题思路代码实现复杂度分析分析问题描述Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would
2020-05-17 12:54:16 196
原创 Leetcode1-100: 15. 3Sum
Leetcode1-100: 15. 3Sum问题描述解题思路代码实现implement 1 Brute forceimplement 2 扩展中心法复杂度分析分析问题描述Given 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:
2020-05-17 12:42:49 207
原创 Leetcode1-100: 14. Longest Common Prefix
Leetcode1-100: 14. Longest Common Prefix问题描述解题思路代码实现复杂度分析分析问题描述Write 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: ["flower","flow","flight"]Ou
2020-05-17 11:58:48 148
原创 Leetcode1-50: 13. Roman to Integer
Leetcode1-50: 13. Roman to Integer问题描述解题思路代码实现复杂度分析分析问题描述Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D
2020-05-15 12:50:56 187
原创 Leetcode1-50: 12. Integer to Roman
Leetcode1-50: 12. Integer to Roman问题描述解题思路代码实现复杂度分析分析问题描述Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D
2020-05-15 12:28:22 131
原创 Leetcode1-50: 11. Container With Most Water
Leetcode1-50: 11. Regular Expression Matching问题描述解题思路Brute force线性算法代码实现implement 1 Brute forceimplement 2 线性算法复杂度分析分析问题描述Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such t
2020-05-15 11:57:27 175
原创 Leetcode1-50: 10. Regular Expression Matching
Leetcode1-50: 10. Regular Expression Matching问题描述解题思路递归法动态编程代码实现implement 1 递归法implement 2 动态规划法复杂度分析分析问题描述Given an input string (s) and a pattern §, implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*
2020-05-14 13:55:04 214
原创 Leetcode1-50: 9. Palindrome Number
Leetcode1-50: 9. Palindrome Number问题描述解题思路逐位取数比较前后一半代码实现implement 1implement 2复杂度分析分析问题描述Determine 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:I
2020-05-14 13:12:26 231
原创 Leetcode1-50: 08, 8. String to Integer (atoi)
@[TOC](Leetcode1-50: 08, 8. String to Integer (atoi))问题描述Implement 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, starting from t
2020-05-14 13:00:00 140
原创 Leetcode1-100: 07. Reverse Integer
Leetcode1-100: 07. Reverse Integer问题描述解题思路代码实现复杂度分析分析问题描述Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing wi
2020-05-14 12:27:00 135
原创 Leetcode1-50: 06, ZigZag Conversion
Leetcode1-100: 06, ZigZag Conversion问题描述解题思路代码实现implement 1 数学总结implement 2 按序添加复杂度分析分析问题描述The 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 le
2020-05-12 10:10:35 161
原创 Leetcode1-100: 05, Longest Palindromic Substring
Leetcode1-100: 05, Longest Palindromic Substring问题描述解题思路代码实现implement 1 动态规划implement 2 扩展中心法implement 3 brute force复杂度分析分析问题描述Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:
2020-05-10 10:27:29 124
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人