일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- iterator
- 운영체제
- Class
- 30. Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- Python Implementation
- kaggle
- 109. Convert Sorted List to Binary Search Tree
- attribute
- Decorator
- Regular Expression
- Python
- data science
- 43. Multiply Strings
- LeetCode
- 프로그래머스
- 시바견
- shiba
- Protocol
- 715. Range Module
- 파이썬
- 컴퓨터의 구조
- 밴픽
- Python Code
- t1
- Convert Sorted List to Binary Search Tree
- Generator
- concurrency
- DWG
Archives
- Today
- Total
Scribbling
[Programmers] 타겟 넘버 본문
https://school.programmers.co.kr/learn/courses/30/lessons/43165
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. Python
def solution(numbers, target):
ret = 0
def dfs(i, acc):
nonlocal ret, target
if i == len(numbers):
ret += acc == target
return
dfs(i+1, acc+numbers[i])
dfs(i+1, acc-numbers[i])
dfs(0, 0)
return ret
2. C++
int ret {0};
void dfs(const vector<int>& numbers, int target, int acc, int idx) {
if (idx == numbers.size()) {
ret += target == acc;
return;
}
dfs(numbers, target, acc+numbers[idx], idx+1);
dfs(numbers, target, acc-numbers[idx], idx+1);
}
int solution(vector<int> numbers, int target) {
dfs(numbers, target, 0, 0);
return ret;
}
'Computer Science > Algorithms & Data Structures' 카테고리의 다른 글
[Programmers] 게임 맵 최단거리 (0) | 2024.06.20 |
---|---|
[Programmers] 네트워크 (0) | 2024.06.20 |
[Programmers] 도둑질 (0) | 2024.06.18 |
[Programmers] 사칙연산 (0) | 2024.06.18 |
[Programmers] 등굣길 (0) | 2024.06.17 |