본문 바로가기

분류 전체보기76

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.
(파이썬) 백준 11654, 11720, 10809, 2675, 1157, 1152, 2908, 5622, 2941, 1316 11654 아스키코드 a = input() print(ord(a)) ord(문자) : 문자에 맞는 아스키 코드 값 chr(숫자) : 숫자에 맞는 아스키 코드 문자 11720 숫자의 합 n = int(input()) num = list(map(int,input())) #입력문을 한 문자씩 int로 변환한 뒤 list로 바꿔서 sum구해줌 print(sum(num)) # 다른 사람 풀이 : map을 바로 sum으로 감싸줘도 같은 결과. n = input() print(sum(map(int,input()))) 10809 알파벳 찾기 a =[-1]*26 # 결과 배열 -1로 초기화 해줌 alp = input() for i, n in enumerate(alp): #enumerate 사용 index랑 값 둘다 가져.. 2021. 6. 27.
반응형