Algorithm
-
[LeetCode]229. Majority Element IIAlgorithm/LeetCode 2021. 9. 29. 10:58
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Follow-up: Could you solve the problem in linear time and in O(1) space? Example 1: Input: nums = [3,2,3] Output: [3] Example 2: Input: nums = [1] Output: [1] Example 3: Input: nums = [1,2] Output: [1,2] Constraints: 1
-
[LeetCode] 169. Majority ElementAlgorithm/LeetCode 2021. 9. 29. 09:34
Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] Output: 2 Constraints: n == nums.length 1
-
[LeetCode]567. Permutation in StringAlgorithm/LeetCode 2021. 9. 26. 21:16
Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1's permutations is the substring of s2. Example 1: Input: s1 = "ab", s2 = "eidbaooo" Output: true Explanation: s2 contains one permutation of s1 ("ba"). Example 2: Input: s1 = "ab", s2 = "eidboaoo" Output: false Constraints: 1 bool: flag = False len_s1 = len(s1..
-
[LeetCode]496. Next Greater Element IAlgorithm/LeetCode 2021. 9. 26. 20:56
The next greater element of some element x in an array is the first greater element that is to the right of x in the same array. You are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2. For each 0