two pointers

Solution)class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: # Two Pointers left, right = 0, len(numbers)-1 while left target: right -= 1 # If the sum is less than target else: left += 1 Problem: ..
Solution) class Solution: def isSubsequence(self, s: str, t: str) -> bool: original, sub = 0, 0 while sub < len(s) and original < len(t): if s[sub] == t[original]: sub += 1 original += 1 if sub == len(s): return True return False Problem: LeetCode Time Complexity: O(m+n) Space Complexity: O(1) Explanation) There are two pointers sub and original that will iterate s and t. We're using two pointer..
정답) class Solution: def isPalindrome(self, s: str) -> bool: left = 0 right = len(s)-1 while left < right: if s[right].isalnum() and s[left].isalnum(): if s[right].lower() != s[left].lower(): return False left += 1 right -= 1 elif not s[left].isalnum(): left += 1 elif not s[right].isalnum(): right -= 1 return True 문제) 문제 출처 팰린드롬 (회문)은 거꾸로 읽어도 똑같은 문장을 뜻합니다. 이 문제에서는 대문자들을 전부 소문자 취급하고 알파벳과 숫자를 제외한 문..
위대한먼지
'two pointers' 태그의 글 목록