array / string 9

[LeetCode 75] Medium - 334. Increasing Triplet Subsequence ☆

334. Increasing Triplet Subsequence Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i  and nums[i]  false. Example 1:Input: nums = [1,2,3,4,5]Output: trueExplanation: Any triplet where i Example 2:Input: nums = [5,4,3,2,1]Output: falseExplanation: No triplet exists.Example 3:Input: nums = [2,1,5,0,4,6]Output: trueExplanation: The triplet (3, 4, 5)..

LeetCode/LeetCode75 2024.11.12

[Prefix Sums] 238. Product of Array Except Self ☆

238. Product of Array Except Self  문제 풀이이 문제는 주어진 배열 nums에서, 각 요소를 제외한 나머지 요소들의 곱을 계산하여 결과 배열을 반환하는 문제입니다. 나눗셈 없이, 시간 복잡도 O(n) 로 해결해야 합니다.문제 조건각 answer[i] 는 배열 nums의 i 번째 요소를 제외한 나머지 요소들의 곱입니다.나눗셈 사용 금지: 단순히 배열 전체 곱을 구한 뒤 각 요소로 나누는 방식은 사용할 수 없습니다.시간 복잡도는 O(n), 공간 복잡도는 O(1) 추가 공간(결과 배열은 제외).풀이 방법1. 아이디어배열의 곱을 효율적으로 계산하려면 다음과 같은 접근법을 사용할 수 있습니다:왼쪽 누적 곱 (prefix product): 각 요소 iii에서, 왼쪽에 있는 모든 요소들의 ..

LeetCode/NeetCode 2024.11.11

[LeetCode 75] Medium - 151. Reverse Words in a String

151. Reverse Words in a String Given an input string s, reverse the order of the words.A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.Return a string of the words in reverse order concatenated by a single space.Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only h..

[LeetCode 75] Easy - 345. Reverse Vowels of a String

345. Reverse Vowels of a String Given a string s, reverse only all the vowels in the string and return it.The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once. Example 1:Input: s = "IceCreAm"Output: "AceCreIm"Explanation:The vowels in s are ['I', 'e', 'e', 'A']. On reversing the vowels, s becomes "AceCreIm".Example 2:Input: s = "leetcode"O..

LeetCode/LeetCode75 2024.11.11

[LeetCode 75] Medium - 1071. Greatest Common Divisor of Strings ☆

1071. Greatest Common Divisor of Strings For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times).Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. Example 1:Input: str1 = "ABCABC", str2 = "ABC"Output: "ABC"Example 2:Input: str1 = "ABABAB", str2 = "ABAB"Outpu..

LeetCode/LeetCode75 2024.11.11