Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Test {
fun isAnagram(str1: CharArray, str2: CharArray): Boolean {
val n1 = str1.size
val n2 = str2.size
if (n1 != n2) return false
str1.sort()
str2.sort()
for (i in 0 until n1) if (str1[i] != str2[i]) return false
return true
}
}
object Fibonacci {
tailrec fun recursiveTail(n: Long, a: Long, b: Long): Long
= if (n < 1) a else recursiveTail(n - 1, b, a + b)
fun iterative(n: Long): Long {
if (n < 2) return n
var minusOne: Long = 1
var minusTwo: Long = 0
var result = minusOne
for (i in 2..n) {
result = minusOne + minusTwo
minusTwo = minusOne
minusOne = result
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment