Leecode 0162. Find Peak Element
162. Find Peak Element题目A peak element is an element that is strictly greater than its neighbors. Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array. You must write an algorithm that runs in O(log n) time. Example...
Leecode 0004. Median of Two Sorted Arrays
4. Median of Two Sorted Arrays题目There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). You may assume nums1 and nums2 cannot be both empty. Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1, 2] nums2 = [3, 4] The median is (2 + 3)/2 = 2.5 题目大意给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m +...
Leecode 0003. Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters题目Given a string, find the length of the longest substring without repeating characters. Example 1: 123Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: 123Input: "bbbbb"Output: 1Explanation: The answer is "b", with the length of 1. Example 3: 1234Input: "pwwkew"Output: 3Explanation: The answer is "wke", with the length of 3. ...
Leecode 0002. Add Two Numbers
2. Add Two Numbers题目You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zeros, except the number 0 itself. Example 1: 123Input: l1 = [2,4,3], l2 = [5,6,4]Output: [7,0,8]Explanation: 342 + 465 = 807. Example 2: 12Input: l1 = [0], l2 = [0]Output: [0] Example...
Leecode 0001.two sum
1. Two Sum题目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 may not use the same element twice. Example: 1234Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1]. 题目大意在数组中找到两个数,它们的和等于给定的目标值 target,并返回这两个数在数组中的下标。要求每个元素只能使用一次,且保证有且仅有一个解。 解题思路方法一:双层循环(暴力枚举)思路 通过双重循环遍历数组中的每一对元素,检查它们的和是否等于目标值 target。外层循环控制第一个元素的索引...