Zero to Hero
article thumbnail
125. Valid Palindrome
Algorithm 2021. 6. 8. 11:20

Valid Palindrome - 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 1. isalnum() class Solution: def isPalindrome(self, s: str) -> bool: stack = [] for char in s: if char.isalnum(): stack.append(char.lower()) if len(stack) % 2 == 1: return stack[:len(stack) // 2] == stack[len(stack)..

article thumbnail
118. Pascal's Triangle
Algorithm 2021. 6. 7. 21:37

Pascal's Triangle - 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 1. 구현 from typing import * class Solution: def generate(self, numRows: int) -> List[List[int]]: answer = [[1]] if numRows == 1: return answer elif numRows == 2: answer.append([1, 1]) return answer else: answer.appe..

article thumbnail
26. Remove Duplicates from Sorted Array
Algorithm 2021. 6. 6. 22:35

Remove Duplicates from Sorted Array - 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 1. 선형 탐색 로직 from typing import * class Solution: def removeDuplicates(self, nums: List[int]) -> int: if not nums: return 0 saved_val, target_index = nums[0], 1 for i in range(len(nums)): if i == 0..

article thumbnail
13. Roman to Integer
Algorithm 2021. 5. 31. 22:28

Roman to Integer - 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 1. 내 Trash Garbage Code class Solution: def romanToInt(self, s: str) -> int: dict1 = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} answer, index = 0, 0 while index < len(s): if s[index] == 'I' an..

article thumbnail
202. Happy Number
Algorithm 2021. 5. 30. 22:22

Happy Number - 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 1. 집합을 이용한 풀이 from functools import reduce class Solution: def isHappy(self, n: int) -> bool: def phase_one(num): return list(map(int, list(str(num)))) def phase_two(input_list): return reduce(lambda acc, cur: acc + cur..

article thumbnail
326. Power of Three
Algorithm 2021. 5. 28. 10:22

Power of Three - 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 1. Iteration class Solution: def isPowerOfThree(self, n: int) -> bool: cur = 0 while True: temp=pow(3,cur) if temp>n: return False if temp==n: return True cur+=1 입력받은 수가 3의 N승의 숫자인지 찾는 문제다. 그냥 3의 N승을 모두 구해서 매칭 되면 반환하게..