加载中...

daily leetcode - search-insert-position - !

题目地址 https://leetcode.com/problems/search-insert-position/ 题目描述 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5 Output: 2 Example 2: Input: [1,3,5,6], 2 Output: 1 Example 3: Input: [1,3,5,6], 7 Output: 4 Example 4: Input: [1,3,5,6], 0 Output: 0 思路 这道题基本没有什么难度,实在不理解为啥还是 Medium 难度的,完完全全的应该是 Easy 啊(貌似现在已经改为 Easy 类了),....

daily leetcode - find-first-and-last-position-of-element-in-sorted-array - !

题目地址 https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ 题目描述 Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O (log n ). If the target is not found in the array, return [-1, -1]. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] 思路 这道题让我们在一个有序整....

daily leetcode - search-in-rotated-sorted-array - !

题目地址 https://leetcode.com/problems/search-in-rotated-sorted-array/ 题目描述 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists in the array. Your algorithm's runtime complexity must be in the order of O (log n ). Example 1: Input: nums = [4,5,6,7,0,1,2], target = 0 Outp....

daily leetcode - longest-valid-parentheses - !

题目地址 https://leetcode.com/problems/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: 2 Explanation: The longest valid parentheses substring is "()" Example 2: Input: ")()())" Output: 4 Explanation: The longest valid parentheses substring is "()()" 思路 这道求最长有效括号比之前那道 Valid Parentheses 难度要大一些,这里还是借助栈来求解,需要定义个 start 变量来记录合法括号串的起始位置,遍历字符串,如果遇到左括号,则将当前下标压....

daily leetcode - next-permutation - !

题目地址 https://leetcode.com/problems/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 (ie, sorted in ascending order). The replacement must be in-place and use only constant extra memory. Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column. 1,2,3 → 1,3,2 3,2....

daily leetcode - substring-with-concatenation-of-all-words - !

题目地址 https://leetcode.com/problems/substring-with-concatenation-of-all-words/ 题目描述 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. Example 1: Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Explanation: Substrings starting at index 0 and 9 are "barfoor" and "foobar" respectively. The output o....

daily leetcode - divide-two-integers - !

题目地址 https://leetcode.com/problems/divide-two-integers/ 题目描述 Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, divisor = -3 Output: -2 Note: Both dividend and divisor will be 32-bit signed integers. The divisor will never be 0. Assume w....

daily leetcode - implement-strstr - !

题目地址 https://leetcode.com/problems/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: 2 Example 2: Input: haystack = "aaaaa", needle = "bba" Output: -1 Clarification: What should we return when needle is an empty string? This is a great question to ask during an interview. For the purpose of this problem, we will return 0 when needle is an....

daily leetcode - remove-element - !

题目地址 https://leetcode.com/problems/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-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length. Example 1: Given _nums_ = [3,2,2,3], _val_ = 3, Your function should return length = 2, with the first two elements....

daily leetcode - remove-duplicates-from-sorted-array - !

题目地址 https://leetcode.com/problems/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 this by modifying the input array in-place with O(1) extra memory. Example 1: Given _nums_ = [1,1,2], Your function should return length = 2, with the first two elements of _nums_ being 1 and 2 respectively. It doesn't matter what you lea....

avatar
Lonus Lan
It's better to burn out than to fade away!
公告
暂无更新通知!
最新文章
网站资讯
文章数目 :
156
已运行时间 :
0 天
本站在线访客数 :
0
本站总访问量 :
0