Last active
February 6, 2020 15:03
-
-
Save vitek999/d8f475379baea9448cb1cd42e20a8b63 to your computer and use it in GitHub Desktop.
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
class Solution { | |
fun isIsomorphic(s: String, t: String): Boolean { | |
return listWithNumber(s.toCharArray()) == listWithNumber(t.toCharArray()) | |
} | |
fun listWithNumber(arr: CharArray): List<Int> { | |
val intList: MutableList<Int> = mutableListOf() | |
val symbols: MutableMap<Char, Int> = mutableMapOf() | |
var counter: Int = 0 | |
for( i in arr){ | |
symbols.putIfAbsent(i, ++counter) | |
intList.add(symbols.get(i)!!) | |
} | |
return intList | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment