본문 바로가기

코딩테스트41

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.
(파이썬) 백준 1978, 2581, 11653, 1929, 4948, 9020, 1085, 3009, 4153 1978 소수찾기 n = int(input()) a = list(map(int,input().split())) count = 0 for num in a: check =True if num x: a = x if b>y: b = y if a>b: print(b) else: print(a) 두줄 x, y, w, h = map(int, input().split()) print(min(x, y, w-x, h-y)) 3009 네번째 점 x1,y1 = map(int,input().split()) x2,y2 = map(int,input().split()) x3,y3 = map(int,input().split()) xArr = [x1,x2,x3] yArr = [y1,y2,y3] for i in range(len(xArr.. 2021. 7. 7.
(파이썬) 백준 1712, 1193, 2869, 10250, 2775, 2839, 1011 1712 손익분기점 A,B,C = map(int, input().split()) if B >=C: print("-1") else: result = A//(C-B) + 1 print(result) 핵심 : A//C-B 1193 분수찾기 n = int(input()) count = 1 while count < n: n-=count count+=1 if count%2==0: down = count-n+1 up = n else: down = n up = count-n+1 print(up,"/",down,sep="") 해당 수의 라인의 찾고 ( 라인은 1씩 증가 ex 1, 2, 3, . .. ) 분모 분자의 특징 찾기. ( 분모 분자가 라인의 짝수 홀수에 따라 반대) 2869 달팽이는 올라가고 싶다 1. 시간초과.. 2021. 7. 6.
반응형