Skip to content

Instantly share code, notes, and snippets.

@vitek999
Last active February 6, 2020 15:03
Show Gist options
  • Save vitek999/d8f475379baea9448cb1cd42e20a8b63 to your computer and use it in GitHub Desktop.
Save vitek999/d8f475379baea9448cb1cd42e20a8b63 to your computer and use it in GitHub Desktop.
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