Created
June 9, 2019 09:21
-
-
Save RotBolt/d02ff1d59bdb8c1cd286cd760a119522 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
private fun String.lastIndexOf(char: Char): Int { | |
var bOpen = 0 // count for open bracket | |
var bClose = 0 // count for close bracket | |
for (i in this.indices) { | |
val currChar = this[i] | |
when { | |
currChar == char && bOpen == bClose -> | |
return this.length - i - 1 | |
currChar == '(' -> bOpen++ | |
currChar == ')' -> bClose++ | |
} | |
} | |
return -1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment