2021/09

[파일명 정렬]-[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...
[로또의 최고 순위와 최저 순위]-[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..
창빵맨
'2021/09 글 목록