리트코드

💡코딩테스트/Leetcode

유효한 팰린드롬 | Valid Palindrome

팰린드롬 팰린드롬이란, 앞뒤가 똑같은 단어나 문장으로, 뒤집어도 같은 말이 되는 단어 또는 문장을 팰린드롬이라고 한다. Valid Palindrome - LeetCode Can you solve this real interview question? Valid Palindrome - A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric cha leetcode.com 정규식을 이용한 풀이 정규식 re를 이용해서 문자와 숫자를 ..

💡코딩테스트/Leetcode

[python|파이썬] 세 수의 합 / 세수의 합이 0이 되는 경우

세 수의 합 3Sum 세 수의 합이 0이 되는 경우를 구하는 문제 💗브루트 포스로 계산하기 각 배열에서 나올 수 있는 모든 경우의 수를 계산하고 답을 도출하는 방법 리트코드에서 해당 방법으로 풀이하면 시간초과에러가 발생한다 😢 result = [] for i in range(len(nums)): for j in range(i+1, len(nums)): for k in range(j+1, len(nums)): if nums[i] + nums[j] + nums[k] == 0: if sorted([nums[i],nums[j],nums[k]]) not in result: result.append(sorted([nums[i],nums[j],nums[k]])) return result 💗투포인터로 계산하기 각 배열..

💡코딩테스트/Leetcode

[python] 문자열 뒤집기 / 문자열 반대로 출력하기

문자열 뒤집기 입력받은 문자열을 반대로 출력해보자👍 ✅ 리스트를 마지막부터 새로운 리스트 안에 넣기 i_list = ["h","e","l","l","o"] o_list = list() while i_list: o_list.append(i_list.pop()) print(o_list) ✅ 투 포인터 사용 i_list = ["h","e","l","l","o"] left, right = 0, len(i_list)-1 while left < right: i_list[left], i_list[right] = i_list[right], i_list[left] left += 1 right -= 1 print(i_list) ✅ reverse() 사용 i_list = ["h","e","l","l","o"] i_list...

💡코딩테스트/Leetcode

[ LeetCode | python ] 11. Container With Most Water

🌏 문제 Container With Most Water - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 물을 최대로 채울 수 있게 하는 기둥 두개를 구하는 문제이다. 👽 풀이 첫번째 접근 class Solution: def maxArea(self, height: List[int]) -> int: start, end = 0, len(height)-1 while start < end: curArea = min(height[start], height[end]) * ..

두_두
'리트코드' 태그의 글 목록