Skip to content

Commit

Permalink
Create 1980-find-unique-binary-string.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
a93a authored Feb 3, 2023
1 parent 63bd0cd commit e07d9ba
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kotlin/1980-find-unique-binary-string.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
fun findDifferentBinaryString(nums: Array<String>): String {
val hs = nums.toSet()
val n = nums.size
var temp = CharArray(nums.size) { '0' }


fun backtrack(i: Int): Boolean {
if(i == n) {
return if(!hs.contains(temp.joinToString(""))) true else false
}
if(backtrack(i+1)) return true
temp[i] = '1'
if(backtrack(i+1)) return true
return false
}

return if(backtrack(0)) temp.joinToString("") else ""
}
}

0 comments on commit e07d9ba

Please sign in to comment.