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)..
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..
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..
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..
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..
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승을 모두 구해서 매칭 되면 반환하게..