본문 바로가기

Programmers31

[python] 네트워크 문제 출처 네트워크 풀이 def solution(n, computers): answer = 0 n = len(computers) while 1: linked = [] for i in range(n): if sum(computers[i]) > 1: for j in range(n): if computers[i][j]: computers[i][j] = 0 computers[j][i] = 0 if i != j: linked.append((i, j)) break if not linked: for y in range(n): if sum(computers[y]): answer += 1 break answer += 1 while linked: y, x = linked.pop(0) for i in range(n): if.. 2019. 9. 1.
[python] 타겟 넘버 문제 출처 타겟 넘버 풀이 풀이 1 def dfs(idx, numbers, result, target): global answer if idx == len(numbers): if result == target: answer += 1 return dfs(idx+1, numbers, result+numbers[idx], target) dfs(idx+1,numbers, result-numbers[idx], target) answer = 0 def solution(numbers, target): dfs(0, numbers, 0, target) return answer 풀이 2 def solution(numbers, target): if not numbers: if target: return 0 return 1 .. 2019. 9. 1.
[python] H-Index 문제 출처 H-Index 풀이 def solution(citations): citations.sort() l = len(citations) for i in range(l): if citations[i] >= l-i: return l-i return 0 2019. 8. 31.
[python] 가장 큰 수 문제 출처 가장 큰 수 풀이 def merge_sort(x): if len(x) < 2: return x m = len(x)//2 lx = merge_sort(x[:m]) rx = merge_sort(x[m:]) result = [] l = r = 0 while l < len(lx) and r < len(rx): if int(rx[r]+lx[l]) < int(lx[l]+rx[r]): result.append(lx[l]) l += 1 else: result.append(rx[r]) r += 1 result += lx[l:] result += rx[r:] return result def solution(numbers): length = len(numbers) for i in range(length): num.. 2019. 8. 31.