[Leetcode] 724 Find Pivot Index (Python)
leetcode2025. 9. 29. 17:16[Leetcode] 724 Find Pivot Index (Python)

문제Find Pivot Index - LeetCode설명Given an array of integers nums, calculate the pivot index of this array.The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applie..

[Leetcode] 2390 Removing Starts From a String (Python)
leetcode2025. 9. 24. 13:11[Leetcode] 2390 Removing Starts From a String (Python)

문제Removing Stars From a String - LeetCode설명You are given a string s, which contains stars *.In one operation, you can:Choose a star in s.Remove the closest non-star character to its left, as well as remove the star itself.Return the string after all stars have been removed.Note:The input will be generated such that the operation is always possible.It can be shown that the resulting string will a..

[Leetcode] 151 Reverse Words in a String (Python)
leetcode2025. 9. 23. 22:37[Leetcode] 151 Reverse Words in a String (Python)

문제Reverse Words in a String - LeetCode설명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 shou..

[Leetcode] 1732 Find the Highest Altitude (Python)
leetcode2025. 9. 22. 22:00[Leetcode] 1732 Find the Highest Altitude (Python)

문제Find the Highest Altitude - LeetCode설명There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i and i + 1 for all (0 . Return the highest altitude of a point.풀이 계획변수 init을 0으로 잡고 gain을 돌..

[Leetcode] 1456 Maximum Number of Vowels in a Substring of Given Length (Python)
leetcode2025. 9. 17. 14:42[Leetcode] 1456 Maximum Number of Vowels in a Substring of Given Length (Python)

문제Maximum Number of Vowels in a Substring of Given Length - LeetCode설명Given 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'.풀이 계획가장 많은 모음이 포함된 k의 길이만큼의 문자열에서의 모음의 갯수를 구하는 문제이다.초기 풀이 (8384ms, 18.22MB)class Solution: def maxVowels(self, s: str, k: int) -> int: vowels="aeio..

[Leetcode] 392 Is Subsequence (Python)
leetcode2025. 9. 16. 21:52[Leetcode] 392 Is Subsequence (Python)

문제Is Subsequence - LeetCode설명Given two strings s and t, return true if s is a subsequence of t, or false otherwise.A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).풀이 계획초기값으로 0을 갖는 변수 ..

[Leetcode] 345 Reverse Vowels of a String (Python)
leetcode2025. 9. 15. 20:13[Leetcode] 345 Reverse Vowels of a String (Python)

문제Reverse Vowels of a String - LeetCode설명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.풀이 계획주어진 문자열에서 모음만 따로 빼서 붙이고 다시 주어진 문자열을 돌면서 모음이 아니면 원래 문자를, 모음이면 모음만 따로 뺀 리스트 마지막 요소를 pop하는 방식으로 리스트를 구성하여 리턴한다.고친 풀이class Solution: def reverseVowels(self, s: str) -> s..

[Leetcode] 643 Maximum Average Subarray I (Python)
leetcode2025. 9. 10. 18:16[Leetcode] 643 Maximum Average Subarray I (Python)

문제Maximum Average Subarray I - LeetCode설명You 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.풀이 계획배열을 n-k만큼 돌면서 모든 경우의 최대합 값을 비교하여 구한다. 마지막까지 돌고 반복문을 나와서 최대합 값을 k로 나눈 값을 리턴하면 될 것으로 생각했다. 배열의..

[Leetcode] 283 Move Zeros (Python)
leetcode2025. 9. 9. 14:28[Leetcode] 283 Move Zeros (Python)

문제https://leetcode.com/problems/move-zeroes 설명Given 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.풀이 계획원본 배열을 수정하는 방식으로 풀어야 한다는 것이 포인트인 것 같다. nums 리스트를 돌면서 i번째 리스트에 0이 있다면 해당 인덱스부터 n-1번째 요소 까지 우측과 바꿔가면서 0이 점점 우측으로 몰리게끔 풀어보았다.초기 풀이class Solution: def moveZ..

[Leetcode] 2348 Number of Zero-Filled Subarrays (Python)
leetcode2025. 8. 20. 00:35[Leetcode] 2348 Number of Zero-Filled Subarrays (Python)

Number of Zero-Filled Subarrays - LeetCode생각리스트를 한번 돌면서 0이 이어진다면 몇번까지 이어지는지 확인하고 이어지는 그룹이 몇개인지도 파악한다.몇번까지 이어지는지만 알면 subarrays 개수는 구할 수 있다.그때그때 0이 이어지는 상태인지 확인이 필요하다.삼각수 배열을 미리 뽑아놓고 갖다 쓰면 좋지 않을까?초기코드class Solution: def zeroFilledSubarray(self, nums: List[int]) -> int: limit = 10**5 triangular_numbers = [n * (n + 1) // 2 for n in range(1, limit + 1)] arr = [] streakF..

728x90
반응형
image