개발/알고리즘35 [codility] Nesting app.codility.com/programmers/lessons/7-stacks_and_queues/nesting/ Nesting coding task - Learn to Code - Codility Determine whether a given string of parentheses (single type) is properly nested. app.codility.com 12프로 ㅋㅋㅋㅋㅋㅋㅋㅋㅋ )( 생각을 못했다ㅎㅎㅎ def solution(S): # write your code in Python 3.6 if len(S) == 0: return 1 if len(S) % 2 == 1: return 0 left = S.count("(") right = S.count(")") if left == ri.. 2021. 2. 20. [codility] Fish app.codility.com/programmers/lessons/7-stacks_and_queues/fish/ Fish coding task - Learn to Code - Codility N voracious fish are moving along a river. Calculate how many fish are alive. app.codility.com 살아있는 모든 fish를 d에 넣었더니 시간초과 하나가 떠서 87프로가 됐다 def solution(A, B): # write your code in Python 3.6 fish = [] for i in range(len(A)): fish.append((A[i],B[i])) while len(fish) > 0: #print(fish) d=[(fish.. 2021. 2. 20. [codility] Brackets app.codility.com/programmers/lessons/7-stacks_and_queues/brackets/ Brackets coding task - Learn to Code - Codility Determine whether a given string of parentheses (multiple types) is properly nested. app.codility.com empty list에서 pop을 시도하면 에러가 발생한다는 교훈을 얻었다 와! 37프로! def solution(S): # write your code in Python 3.6 d = [] for i in S: if i == "[": d.append(1) elif i == "(": d.append(2) elif i == ".. 2021. 2. 19. [codility] Triangle app.codility.com/programmers/lessons/6-sorting/triangle/ Triangle coding task - Learn to Code - Codility Determine whether a triangle can be built from a given set of edges. app.codility.com 삼각형이 될 조건은 ac면 바로 1 def solution(A): # write your code in Python 3.6 A.sort() for i in range(len(A)-2): if A[i]+A[i+1] > A[i+2]: return 1 return 0 2021. 2. 19. [codility] NumberOfDiscIntersections app.codility.com/c/run/trainingPURC2R-CMA/ Codility Your browser is not supported You should use a supported browser for the test. Read more app.codility.com 음... 문제 이해를 잘못했다 교차점의 개수를 구하는 줄 알앗는데 디스크끼리 겹쳐지는 개수를 구하는 거 였다 (디스크 안에 디스크가 있어도 겹쳐져 있다고 생각함) ↓ 틀린 풀이 def solution(A): # write your code in Python 3.6 count = 0 for i in range(len(A)-1): print("----") for j in range(i+1,len(A)): print(i+A[i], .. 2021. 2. 19. [codility] MaxProductOfThree app.codility.com/programmers/lessons/6-sorting/max_product_of_three/ MaxProductOfThree coding task - Learn to Code - Codility Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R). app.codility.com 원소 3개를 뽑아서 곱했을 때 가장 큰 값을 출력 -> 음수*음수*양수/ 양수*양수*양수 두가지 경우가 있다 sorting을 한번 해주고 음수가 2개 이상일 때 음수*음수*양수 와 양수*양수*양수 중 큰 값이 답 나머지는 제일 큰 양수의 곱이 답 def solution(A): # write your code in Python 3.6 a = sorted(A).. 2021. 2. 19. 이전 1 2 3 4 ··· 6 다음