전체 글

[숫자의 표현] My answer def solution(n): answer = 0 for i in range(1,n+1): answer+=sums(i,n) return answer def sums(n,tmp): sumt=0 while(sumt=10): # 11진법 이상부터는 변환해서 넣는다 tmp.append(str(trans[j%n])) else: tmp.append(j%n) j//=n if(j==0): break tmp.reverse() tmp2+=[i for i in tmp] tmp=[] i+=1 for i in range(p-1,p+m*t-1,m): # 이용자가 말해야 되는 순번 인덱스에 저장된 숫자를 말한다. answer+=str(tmp2[i]) return answer Another answ..
[N개의 최소공배수] My answer def gcd(a,b): if(b>a): a,b=b,a a=a%b if(a==0): return b return gcd(b,a) def solution(arr): if(len(arr)%2==1): arr.append(1) while(len(arr)!=1): for i in range(0,len(arr)-1,2): arr[i]=arr[i]*arr[i+1]//gcd(arr[i],arr[i+1]) arr[i+1]=0 while(arr.count(0)!=0): arr.remove(0) return arr[0] Another answer def gcd(a, b): if b == 0: return a return gcd(b, a%b) def solution(arr): arr...
[로또의 최고 순위와 최저 순위]-[2021 Dev-Matching: 웹 백엔드 개발자] My answer def solution(lottos, win_nums): count=0 rank={6:1,5:2,4:3,3:4,2:5,1:6,0:6} for i in lottos: if(i in win_nums): count+=1 answer=[rank[count+lottos.count(0)],rank[count]] return answer Another answer def solution(lottos, win_nums): rank = {0: 6,1: 6,2: 5,3: 4,4: 3,5: 2,6: 1} return [rank[len(set(lottos) & set(win_nums)) + lottos.count(0)]..
[숫자 문자열과 영단어]-[2021 카카오 채용연계형 인턴십] My answer def solution(s): code=["zero","one","two","three","four","five","six","seven","eight","nine"] answer,tmp = "", "" for i in range(len(s)): if(s[i].isdigit()): answer+=s[i] else: tmp+=s[i] if(tmp!="" and tmp in code): for i in range(len(code)): if(tmp==code[i]): answer+=str(i) tmp="" return int(answer) Another answer num_dic = {"zero":"0", "one":"1", "t..
[크레인 인형뽑기 게임]-[2019 카카오 개발자 겨울 인턴십] My answer def solution(board, moves): answer,cnt = 0, 0 tmp=[[0 for i in board] for j in board] array2=[0]*(len(board)**2) for i in range(len(board)): for j in range(len(board)): tmp[i][j]=board[j][i] for i in moves: for j in range(len(tmp[0])): if(tmp[i-1][j]!=0): array2[cnt]=tmp[i-1][j] tmp[i-1][j]=0 # 두개씩 만들어지면 터뜨리는 과정 if(cnt!=0 and array2[cnt-1]==array2[cn..
[K번째 수] My answer def solution(array, commands): tmp,answer = [],[] for i in commands: tmp=array[i[0]-1:i[1]] tmp.sort() answer.append(tmp[i[2]-1]) tmp=[] return answer Another answer def solution(array, commands): return [sorted(array[a[0]-1:a[1]])[a[2]-1] for a in commands] -------------------------------------------------------------------- def solution(array, commands): return list(map(lambd..
[폰켓몬]-[찾아라 프로그래밍 마스터] My answer def solution(nums): tmp=set(nums) if(len(nums)/2>=len(tmp)): return len(tmp) else: return len(nums)//2 Another answer def solution(nums): return min(len(set(nums)), len(nums)//2) [체육복]-[탐욕법(Greedy)] My answer def solution(n, lost, reserve): answer = 0 cloth = [1]*n for i in lost: cloth[i-1]-=1 for i in reserve: cloth[i-1]+=1 i=0 while(i!=len(cloth)): if(cloth[i]>1..
창빵맨
Let's be Developers