![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
精选Top面试题
str_818
这个作者很懒,什么都没留下…
展开
-
【Leetcode】33. 搜索旋转排序数组(Search in Rotated Sorted Array)
Leetcode - 33 Search in Rotated Sorted Array (Medium)题目描述:给定一个旋转的有序数组,例如有序数组 [0,1,2,4,5,6,7] 经一次旋转后可得 [4,5,6,7,0,1,2] ,再给定一个 target 值,返回 target 值在数组中的下标,如果不在返回 -1,假设数组中无重复元素,时间复杂度要求为 O(logn)。Input:...原创 2019-06-06 09:40:03 · 239 阅读 · 0 评论 -
【Leetcode】14. 最长公共前缀(Longest Common Prefix)
Leetcode - 14 Longest Common Prefix (Easy)Input: ["flower","flow","flight"]Output: "fl"public String longestCommonPrefix(String[] strs) { if (strs.length == 0) return ""; String prefix = s...原创 2019-06-03 22:49:18 · 110 阅读 · 0 评论 -
【Leetcode】15. 三数之和(3Sum)
Leetcode - 15 3Sum (Medium)题目描述:找出数组中三数和为 0 的组合。Given array nums = [-1, 0, 1, 2, -1, -4],A solution set is:[ [-1, 0, 1], [-1, -1, 2]]解题思路:注意去重。public List<List<Integer>> three...原创 2019-06-04 08:21:35 · 131 阅读 · 0 评论 -
【Leetcode】17. 电话号码的字母组合(Letter Combinations of a Phone Number)
Leetcode - 17 Letter Combinations of a Phone Number (Medium) Input: "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].Map<String, String> map = new HashMap<String, Str...原创 2019-06-04 08:51:24 · 154 阅读 · 0 评论 -
【Leetcode】19. 删除链表的倒数第 n 个节点(Remove Nth Node From End of List)
Leetcode - 19 Remove Nth Node From End of List (Medium)Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becomes 1->2->3->...原创 2019-06-04 09:02:57 · 138 阅读 · 0 评论 -
【Leetcode】20.有效的括号(Valid Parenthese)
Leetcode - 20 Valid Parenthese (Easy)题目描述:给定字符串,判断括号是否有效。Input: "()[]{}"Output: truepublic boolean isValid(String s) { Stack<Character> stack = new Stack<>(); for (Character c...原创 2019-06-04 22:16:07 · 125 阅读 · 0 评论 -
【Leetcode】21. 合并两个有序链表(Merge Two Sorted Lists)
Leetcode - 21 Merge Two Sorted Lists (Easy)Input: 1->2->4, 1->3->4Output: 1->1->2->3->4->4解法一:迭代public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode d...原创 2019-06-04 22:25:19 · 126 阅读 · 0 评论 -
【Leetcode】22. 生成括号(Generate Parentheses)
Leetcode - 22 Generate Parentheses (Medium)题目描述:给定整数 n,生成包含 n 个括号合法字符串的所有组合。[ "((()))", "(()())", "(())()", "()(())", "()()()"]解题思路:结合合法括号的特性。public List<String> generateParenthe...原创 2019-06-04 22:34:28 · 143 阅读 · 0 评论 -
【Leetcode】23. 合并 k 个有序链表(Merge k Sorted Lists)
Leetcode - 23 Merge k Sorted Lists (Hard)Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4->4->5->6解题思路:这道题类似之前的合并两个有序链表,可以逐个两两合并,也可以每次取出链表头部的最小节点,我也...原创 2019-06-04 22:52:53 · 192 阅读 · 0 评论 -
【Leetcode】26. 删除有序数组中的重复项(Remove Duplicates from Sorted Array)
Leetcode - 26 Remove Duplicates from Sorted Array (Easy)Given nums = [0,0,1,1,1,2,2,3,3,4],Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3,...原创 2019-06-05 08:32:15 · 468 阅读 · 0 评论 -
【Leetcode】28. 实现 strStr()(Implement strStr())
Leetcode - 28. Implement strStr() (Easy)题目描述:返回匹配字符串首字母的下标,不存在返回 -1。Input: haystack = "hello", needle = "ll"Output: 2解题思路:注意 needle 长度为 0 时返回 0,而不是 -1。public int strStr(String haystack, String n...原创 2019-06-05 08:48:20 · 131 阅读 · 0 评论 -
【Leetcode】42. 接雨水(Trapping Rain Water)
Leetcode - 42 Trapping Rain Water (Hard)题目描述:给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 Input: [0,1,0,2,1,0,1,3,2,1,2,1]Output: 6解题思路:双指针public int trap(int[] height) { int left = ...原创 2019-06-09 09:19:56 · 235 阅读 · 0 评论 -
【Leetcode】13. 罗马数字转整数(Roman to Integer)
Leetcode - 13 Roman to Integer (Easy)题目描述:Symbol ValueI 1V 5X 10L 50C 100D 500M 1000I can be place...原创 2019-06-03 10:22:33 · 131 阅读 · 0 评论 -
【Leetcode】34. 在排序数组中查找元素的第一个和最后一个位置(Find First and Last Position of Element in Sorted Array)
Leetcode - 34 Find First and Last Position of Element in Sorted Array (Medium)题目描述:给定一个有序序列与一个 target 值,求出 target 在有序序列中的区间,时间复杂度要求为 O(logn),若没有 target 值,则返回 [-1, -1]。Input: nums = [5,7,7,8,8,10], t...原创 2019-06-06 09:56:32 · 163 阅读 · 0 评论 -
【Leetcode】36. 有效的数独(Valid Sudoku)
Leetcode - 36 Valid Sudoku (Medium)题目描述:给定一个 9 × 9 的不完整数独数组,判定是否合法。解题思路:判断每一行、每一列和每个 3 × 3 单元格是否有重复的数字。public boolean isValidSudoku(char[][] board) { boolean[][] row = new boolean[9][9]; bo...原创 2019-06-06 10:19:40 · 157 阅读 · 0 评论 -
【Leetcode】1. 两数之和(Two Sum)
Leetcode - 1 Two Sum (Easy)题目描述:给定一个数组,返回相加和为 target 的两个元素的下标。Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].public int[] twoSum(int[] nums, int tar...原创 2019-06-02 10:52:19 · 149 阅读 · 0 评论 -
【Leetcode】2. 两数相加(Add Two Numbers)
Leetcode - 2 Add Two Numbers (Medium)题目描述:使用链表表示两个正整数,返回两正整数相加结果,使用链表表示。Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8Explanation: 342 + 465 = 807.public ListNode addT...原创 2019-06-02 11:06:21 · 205 阅读 · 0 评论 -
【Leetcode】3. 无重复字符的最长子串(Longest Substring Without Repeating Characters)
Leetcode - 3 Longest Substring Without Repeating Characters (Medium)Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. 解题思路:使用 HashMap 记录出现字符的位置,利用双指针滑动窗口记录子串的长度。...原创 2019-06-02 11:28:31 · 133 阅读 · 0 评论 -
【Leetcode】46. 全排列(Permutations)
Leetcode - 46 Permutations (Medium)题目描述: 给定无重复的整数序列,返回所有全排列的可能。Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]public List<List<Integer>> per...原创 2019-06-08 22:36:26 · 150 阅读 · 0 评论 -
【Leetcode】48. 旋转图像(Rotate Image)
Leetcode - 48 Rotate Image (Medium)题目描述:将一个 n × n 的矩阵旋转 90°,不能使用额外的辅助空间。Given input matrix = [ [1,2,3], [4,5,6], [7,8,9]],rotate the input matrix in-place such that it becomes:[ [7,4,1]...原创 2019-06-08 22:44:32 · 205 阅读 · 0 评论 -
【Leetcode】41. 缺失的第一个正整数(First Missing Positive)
Leetcode - 41 First Missing Positive (Hard)Input: [3,4,-1,1]Output: 2public int firstMissingPositive(int[] nums) { int i = 0; while (i < nums.length) { if (nums[i] >= 1 &...原创 2019-06-08 23:06:54 · 272 阅读 · 0 评论 -
【Leetcode】10. 正则表达式匹配(Regular Expression Matching)
Leetcode - 10 Regular Expression Matching (Hard)题目描述:. 表示任意字符,* 表示它前面的字符可以出现任意次(包含 0 次)。Input:s = "aab"p = "c*a*b"Output: trueExplanation: c can be repeated 0 times, a can be repeated 1 time. Th...原创 2019-06-03 09:56:43 · 129 阅读 · 0 评论 -
【Leetcode】11. 盛最多水的容器(Container With Most Water)
Leetcode - 11 Container With Most Water (Medium)题目描述:找出两条线,使得构成的容器能够容纳最多的水。 public int maxArea(int[] height) { int max = 0, i = 0, j = height.length - 1; while (i < j) { max = ...原创 2019-06-03 10:07:08 · 124 阅读 · 0 评论 -
【Leetcode】29. 两数相除(Divide Two Integers)
Leetcode - 29 Divide Two Integers (Medium)题目描述:不使用乘法、除法和 mod 运算符。Input: dividend = 10, divisor = 3Output: 3解题思路:注意整数溢出的情况, 可以利用二分的思想优化求解。public int divide(int dividend, int divisor) { int si...原创 2019-06-05 09:09:46 · 184 阅读 · 0 评论