Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 백준 파이썬
- 백준 19238
- 프로래머스
- spring oauth
- 프로그래머스
- 파이썬
- 백준
- re.split
- 백준 15685
- 백준 17626
- JVM
- spring cloud
- spring security
- Kotlin
- 백준 17779
- 백준 16235
- Spring
- 백준 16236
- 웹어플리케이션 서버
- MySQL
- Spring Boot
- 백준 16719
- java
- sql 기술면접
- JPA
- MSA
- with recursive
- java 기술면접
- Coroutine
- springboot
Archives
- Today
- Total
시작이 반
[프로그래머스] 타겟넘버 (python 파이썬) 본문
SMALL

재귀 문제이다.
dfs로 문제를 풀었다.
한 숫자에 대해서 양수 or 음수를 더할수 있다.
마지막 depth에 도달했을때 target과 같으면 count 를 증가시킨다.
count = 0
def solution(numbers, target):
dfs(numbers, target, 0, 0)
return count
def dfs(numbers, target, depth, result):
global count
if depth == len(numbers):
if result == target:
count += 1
return
left = result - numbers[depth]
right = result + numbers[depth]
dfs(numbers, target, depth+1, left)
dfs(numbers, target, depth+1, right)
LIST
'알고리즘 > Programmers' 카테고리의 다른 글
[프로그래머스] 정수 삼각형(python 파이썬) (0) | 2021.03.11 |
---|---|
[프로그래머스] 입국심사(python 파이썬) (0) | 2021.03.11 |
[프로그래머스] 여행경로(python 파이썬) (0) | 2021.03.10 |
[프로그래머스] 단어 변환(python 파이썬) (0) | 2021.03.10 |
[프로그래머스] 네트워크(python 파이썬) (0) | 2021.03.10 |