BFS


Overview


BFS(Breadth First Search)

practice

func solution(numbers []int, target int) int {
    result := 0
    result += recursive(numbers, 0, 0, target)
    return result
}

func recursive(numbers []int, index int, sum int, target int) int{
    result := 0
    if index == len(numbers) {
        if sum == target {
            return 1
        }
        return 0
    }
    result += recursive(numbers, index + 1, sum + numbers[index], target)
    result += recursive(numbers, index + 1, sum - numbers[index], target)
    return result
}

reference


https://programmers.co.kr/learn/courses/30/lessons/43165