LeetCode 解题报告 (33,81,153,154)-- 二分搜索找旋转数组特定值
本文主要讲述如何在一个 Rotated Sorted Array
中找到特定的值,Rotated Sorted Array
指旋转了的数组,如 4 5 6 7 0 1 2
就是 0 1 2 4 5 6 7
的一个旋转数组。正常情况下遍历一遍即可,但是这样的时间复杂度为 \(O(n)\), 但是本文主要讲述通过二分查找将时间复杂度降到 \(O(log_2n)\)。
本文主要讲述如何在一个 Rotated Sorted Array
中找到特定的值,Rotated Sorted Array
指旋转了的数组,如 4 5 6 7 0 1 2
就是 0 1 2 4 5 6 7
的一个旋转数组。正常情况下遍历一遍即可,但是这样的时间复杂度为 \(O(n)\), 但是本文主要讲述通过二分查找将时间复杂度降到 \(O(log_2n)\)。
原题如下:
>Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
原题如下:
>Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
原题如下:
>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(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.
据说这是面试中被问频率非常高的一个问题,下面做简单的记录:
Java 中的 java.util.Iterator
和 java.util.Enumeration
均可用来遍历 Java 中的集合框架(list,map,set 等)。
原题如下:
>Divide two integers without using multiplication, division and mod operator.
If it is overflow, return MAX_INT.
原题如下:
>Given an array and a value, 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 in place with constant memory.
LeetCode 解题报告 (26)-- 消除有序数组中重复值 (常数空间)
原题如下:
>Given a sorted array, 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 this in place with constant memory.
LeetCode 解题报告 (23)-- 合并 k 个有序数组
原题如下:
>Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.0%