Created
June 27, 2022 19:48
-
-
Save gordinmitya/9662d3b9ecdbaa8bf9303110af0a070f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
fun doit(array: CharArray, left: Int, balance: Int) { | |
if (left == 0) { | |
println(Arrays.toString(array)) | |
return | |
} | |
if (left > balance) { | |
array[array.size - left] = '(' | |
doit(array, left - 1, balance + 1) | |
} | |
if (balance > 0) { | |
array[array.size - left] = ')' | |
doit(array, left - 1, balance - 1) | |
} | |
} | |
val len = 3 * 2 | |
val array = CharArray(len) { '-' } | |
doit(array, len, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment