Leetcode#862. Shortest Subarray with Sum at Least K
ProblemGiven an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return -1.
A subarray is a contiguous part of an array.
Example 1:
123Input: nums = [1], k = 1Output: 1
Example 2:
123Input: nums = [1,2], k = 4Output: -1
Example 3:
123Input: nums = [2,-1,2], k = 3Output: 3
Constraints:
1 <= nums.length <= 10^5
10^5 <= nums[i] <= 10^5
1 <= k <= 10^9
Solve想破頭 簡單說就是 找到第一組解後 ...
Leetcode#76. Minimum Window Substring
ProblemGiven two strings s and t of lengths m and n respectively, return the minimum window
substring
of
1s
such that every character in
1t
(including duplicates) is included in the window
. If there is no such substring, return
the empty string
1""
.
The testcases will be generated such that the answer is unique.
Example 1:
1234Input: s = "ADOBECODEBANC", t = "ABC"Output: "BANC"Explanation: The minimum window substring "BANC" includes 'A ...
Leetcode#1493. Longest Subarray of 1's After Deleting One Element
ProblemGiven a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1‘s in the resulting array. Return 0 if there is no such subarray.
Example 1:
1234Input: nums = [1,1,0,1]Output: 3Explanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's.
Example 2:
1234Input: nums = [0,1,1,1,0,1,1,0,1]Output: 5Explanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest suba ...
Leetcode#1456. Maximum Number of Vowels in a Substring of Given Length
ProblemGiven a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.
Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.
Example 1:
1234Input: s = "abciiidef", k = 3Output: 3Explanation: The substring "iii" contains 3 vowel letters.
Example 2:
1234Input: s = "aeiou", k = 2Output: 2Explanation: Any substring of length 2 contains 2 vowels.
Example 3:
1234Input: s = &qu ...
Leetcode#643. Maximum Average Subarray I
ProblemYou are given an integer array nums consisting of n elements, and an integer k.
Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.
Example 1:
1234Input: nums = [1,12,-5,-6,50,3], k = 4Output: 12.75000Explanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75
Example 2:
123Input: nums = [5], k = 1Output: 5.00000
Constraints:
n == nums.length
1 < ...