programmers
-
[Algorithm - 프로그래머스] Python 전력망을 둘로 나누기Programming/Algorithm 2021. 11. 23. 21:06
문제 (LV.2) https://programmers.co.kr/learn/courses/30/lessons/86971 코드 answer = 0 def bfs(wires, checked, num, cnt): global answer q = [num] while len(q) != 0: cur = q.pop(0) for i in range(0, len(wires)): if wires[i][0] == cur: if checked[wires[i][1]] == 0: checked[wires[i][1]] = 1 q.append(wires[i][1]) cnt += 1 elif wires[i][1] == cur: if checked[wires[i][0]] == 0: checked[wires[i][0]] = 1 q.ap..
-
[Algorithm - 프로그래머스] Python 숫자 문자열과 영단어Programming/Algorithm 2021. 10. 21. 00:40
문제 (LV.1) https://programmers.co.kr/learn/courses/30/lessons/81301 코드 def solution(s): answer = '' num = {"zero" : '0', "one" : '1', "two" : '2', "three" : '3' , "four" : '4', "five" : '5', "six" : '6', "seven" : '7' , "eight" : '8', "nine" : '9' } tmp_words = "" for i in s: if i.isdigit(): answer += i continue tmp_words += i if tmp_words in num.keys(): # dictionary key 안에 단어가 존재한다면 answer += nu..