uploaded at 2022. 12. 28. 오후 6:58:48
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/43165
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
class Solution {
|
||||||
|
|
||||||
|
public int solution(int[] numbers, int target) {
|
||||||
|
int answer = 0;
|
||||||
|
List<Integer> leaves = List.of(0);
|
||||||
|
for(int num : numbers){
|
||||||
|
List<Integer> tmp = new ArrayList<>();
|
||||||
|
for(int parent : leaves){
|
||||||
|
tmp.add(parent + num);
|
||||||
|
tmp.add(parent - num);
|
||||||
|
}
|
||||||
|
leaves = tmp;
|
||||||
|
}
|
||||||
|
for(int leaf : leaves){
|
||||||
|
if(leaf==target) answer ++;
|
||||||
|
}
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user