Skip to content

Instantly share code, notes, and snippets.

@joeke80215
Last active October 7, 2018 03:53
Show Gist options
  • Select an option

  • Save joeke80215/bad7da554bc38ffcbc7f44faf343d373 to your computer and use it in GitHub Desktop.

Select an option

Save joeke80215/bad7da554bc38ffcbc7f44faf343d373 to your computer and use it in GitHub Desktop.
kotlin backtrack
class CombineHandler {
var subsetArray: IntArray
val SIZE: Int = 5
init {
subsetArray = IntArray(SIZE)
}
fun backtrack (n: Int,size: Int) {
if (n == SIZE) {
for (i in 0..size - 1) {
print("${subsetArray[i]} ")
}
println()
return
}
subsetArray[size] = n
backtrack(n + 1,size + 1)
backtrack(n + 1,size)
}
}
fun main () {
backtrack(0,0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment