[프로그래머스/Python] 타겟넘버(DFS)
전형적인 DFS 문제다. 그나저나 전역변수 쓰는법 몰라서 오래 걸렸다. answer = 0 def dfs(numbers, target, cnt, num): global answer if cnt == len(numbers): if num == target: answer+=1 return dfs(numbers,target,cnt+1,num+numbers[cnt]) dfs(numbers,target,cnt+1,num-numbers[cnt]) return def solution(numbers, target): global answer dfs(numbers, target, 0, 0) return answer
[프로그래머스/Python] 모의고사(단순구현)
def correct_counter(supoza, answers): cnt=0 for i in range(len(answers)): if answers[i] == supoza[i%len(supoza)]: cnt+=1 return cnt def solution(answers): supoza1 = [1, 2, 3, 4, 5] supoza2 = [2, 1, 2, 3, 2, 4, 2, 5] supoza3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] cnt=[] cnt.append(correct_counter(supoza1,answers)) cnt.append(correct_counter(supoza2,answers)) cnt.append(correct_counter(supoza3,answers))..