forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 1980-find-unique-binary-string.kt
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 "" | ||
} | ||
} |