kt: add «1980. Find Unique Binary String»
URL: https://leetcode.com/problems/find-unique-binary-string/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
b4ae6a0820
commit
9fbca34230
1 changed files with 12 additions and 0 deletions
12
kt/find-unique-binary-string.kt
Normal file
12
kt/find-unique-binary-string.kt
Normal file
|
@ -0,0 +1,12 @@
|
|||
class Solution {
|
||||
companion object {
|
||||
private val MAPPING: Map<Char, Char> = mapOf('0' to '1', '1' to '0')
|
||||
}
|
||||
|
||||
fun findDifferentBinaryString(nums: Array<String>): String =
|
||||
nums
|
||||
.withIndex()
|
||||
.fold(StringBuilder(nums.size)) { sb, it ->
|
||||
sb.append(MAPPING[it.value[it.index]]!!)
|
||||
}.toString()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue