Skip to content

Instantly share code, notes, and snippets.

@GeorgCantor
Created March 13, 2021 13:49
Show Gist options
  • Save GeorgCantor/27b26555afadfd42d128d8f66d4462ed to your computer and use it in GitHub Desktop.
Save GeorgCantor/27b26555afadfd42d128d8f66d4462ed to your computer and use it in GitHub Desktop.
fun countSubstrings(s: String): Int {
var c = 0
for (i in s.indices) {
val sb = StringBuilder()
for (j in i until s.length) if (sb.append(s[j]).toString() == sb.toString().reversed()) c++
}
return c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment