본문 바로가기

코딩테스트/LeetCode 문제3

LeetCode [알고리즘] Roman to Integer 문제 https://leetcode.com/problems/roman-to-integer/ 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 나의 풀이 class Solution: def romanToInt(self, s: str) -> int: arr = list(s) a = [] result = 0 for i,n in enumerate(arr): if n == 'I': #1 if i+1 2021. 12. 22.
LeetCode [알고리즘] Palindrome Number 문제 입력된 숫자가 회문 숫자인지 확인하시오 (회문 ex) (o) -> 010, 123321, (x) ->123 , 1100 나의 풀이 class Solution: def isPalindrome(self, x: int) -> bool: if x bool: if x bool: if x0: newNum = newNum * 10 + x%10 x = x//10 return newNum == inputNum x를 10으로 나누어 주어 1의 자릿수 부터 거꾸로 새로운 변수를 생성해 준다. 해당 변수와 x를 비교하여 결과 값을 리턴해 준다. 접근 방식은 비슷한데 나는 왜이리 복잡하게 풀었을까. 2021. 12. 22.
LeetCode [알고리즘] Two Sum 문제 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. int형 배열 nums와 int형 변수 target이 주어졌을 때, 더해서 target이 되는 두 수의 인덱스를 반환해라. You may assume that each input would have exactly one solution, and you may not use the same element twice. 각 입력에 하나의 정확한 답이 있다고 가정한다. 그리고 같은 요소를 두 번 사용하지 않는다. You can return the answer in any order. 순서 상.. 2021. 12. 21.
반응형