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#684. Redundant Connection
ProblemIn this problem, a tree is an undirected graph that is connected and has no cycles.
You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed. The graph is represented as an array edges of length n where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the graph.
Return an edge that can be removed so that ...
Leetcode#200. Number of Islands
ProblemGiven an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Example 1:
12345678Input: grid = [ ["1","1","1","1","0"], ["1","1","0","1","0"] ...
Leetcode#5. Longest Palindromic Substring
ProblemGiven a string s, return the longest
palindromic
substring
in
1s
.
Example 1:
1234Input: s = "babad"Output: "bab"Explanation: "aba" is also a valid answer.
Example 2:
123Input: s = "cbbd"Output: "bb"
Constraints:
1 <= s.length <= 1000
s consist of only digits and English letters.
Solve123456789101112131415161718192021class Solution: def longestPalindrome(self, s: str) -> str: res = "" for i in range ...
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 < ...
Leetcode#283. Move Zeroes
ProblemGiven an integer array nums, move all 0‘s to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of the array.
Example 1:
123Input: nums = [0,1,0,3,12]Output: [1,3,12,0,0]
Example 2:
123Input: nums = [0]Output: [0]
Constraints:
1 <= nums.length <= 10^4
2^31 <= nums[i] <= 2^31 - 1
Follow up:
Could you minimize the total number of operations done?
Solve123456789101112class Solution: def mov ...
Leetcode#1768. Merge Strings Alternately
ProblemYou are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.
Return the merged string.
Example 1:
1234567Input: word1 = "abc", word2 = "pqr"Output: "apbqcr"Explanation: The merged string will be merged as so:word1: a b cword2: p q rmerged: a p b q c r
Example 2:
1234567Input: word1 = & ...
Leetcode#435. Non-overlapping Intervals
ProblemGiven an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
Example 1:
1234Input: intervals = [[1,2],[2,3],[3,4],[1,3]]Output: 1Explanation: [1,3] can be removed and the rest of the intervals are non-overlapping.
Example 2:
1234Input: intervals = [[1,2],[1,2],[1,2]]Output: 2Explanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.
...