코딩테스트

[방문 길이]-[Summer/Winter Coding(~2018)] My answer def solution(dirs): answer = set() posx,posy,tmpx,tmpy=0,0,0,0 for i in dirs: tmpx,tmpy=posx,posy if(i=='U' and posy!=5): posy+=1 elif(i=='D' and posy!=-5): posy-=1 elif(i=='R' and posx!=5): posx+=1 elif(i=='L' and posx!=-5): posx-=1 if((posx,posy)==(tmpx,tmpy)): continue answer.add((posx,posy,tmpx,tmpy)) answer.add((tmpx,tmpy,posx,posy)) return le..
[방금그곡]-[2018 KAKAO BLIND RECRUITMENT] My answer # 총 재생길이를 구해주는 함수 def timecalc(a,b): tmp,tmp2=[],[] tmp=a.split(':') tmp2=b.split(':') tmp=[int(i) for i in tmp] tmp2=[int(i) for i in tmp2] return (tmp2[0]-tmp[0])*60+tmp2[1]-tmp[1] '''#을 치환해주는 함수''' def substitution(a): alt={'C#':'H','D#':'I','F#':'J','G#':'K','A#':'L','E#':'M'} i=0 tmp="" while('#' in a): if(a[i]=='#'): tmp=a[i-1]+a[i] a=a[:i-1]..
[파일명 정렬]-[2018 KAKAO BLIND RECRUITMENT] My answer def solution(s): answer=[] tmp=[[ 0 for i in range(4)] for j in s] for index,i in enumerate(s): for j in range(len(i)): if(i[j].isdigit()==1): tmp[index][0]=i[:j].upper() for k in range(j,len(i)): tmp[index][3]=index if(k==len(i)-1): tmp[index][1]=int(i[j:]) break if(k==j+5 or i[k].isdigit()==0): tmp[index][1]=int(i[j:k]) tmp[index][2]=i[k:] brea..
[올바른 괄호] My answer-효율성 저하 def solution(s): answer = True s=list(s) #우선 갯수가 다르거나 맨앞이 ) 이거나 맨뒤가 ( 이면 바로 끝냄 answer= False if (s.count('(')!=s.count(')') or s[0]==')' or s[-1]=='(') else True if(answer==False): return answer while(len(s)!=0): if(s[0]=='('): for j in range(1,len(s)): if(s[j]==')'): flag=1 break if(flag==0): return False else: del s[0],s[j-1] flag=0 else: return False return True Anot..
[숫자의 표현] 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...
창빵맨
'코딩테스트' 카테고리의 글 목록 (34 Page)