코딩테스트/프로그래머스[Python]

[방문 길이]-[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]..
[올바른 괄호] 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...
[로또의 최고 순위와 최저 순위]-[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)]..
창빵맨
'코딩테스트/프로그래머스[Python]' 카테고리의 글 목록