Skip to content

Instantly share code, notes, and snippets.

@cg4jins
Created July 19, 2019 09:45
Show Gist options
  • Save cg4jins/165358b2411974e278963079e0d2c182 to your computer and use it in GitHub Desktop.
Save cg4jins/165358b2411974e278963079e0d2c182 to your computer and use it in GitHub Desktop.
class Solution {
fun solution(strings: Array<String>, n: Int): Array<String> {
var i = strings.size - 1
while (i > 0) {
var j = 0
while (j < i) {
var temp: String
if (strings[j][n] > strings[j + 1][n]) {
temp = strings[j]
strings[j] = strings[j + 1]
strings[j + 1] = temp
}
if (strings[j][n] == strings[j + 1][n] && strings[j] > strings[j + 1]){
temp = strings[j]
strings[j] = strings[j + 1]
strings[j + 1] = temp
}
j++
}
i--
}
return strings
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment