Kotlin Leetcode - 2367. Number of Arithmetic Triplets
class Solution {
fun arithmeticTriplets(nums: IntArray, diff: Int): Int {
}
}
解題思路
這一題考的是對陣列的處理
利用 Kotlin 內建的 count
跟 contains
可以很快的解決
Kotlin 參考解答
class Solution {
fun arithmeticTriplets(nums: IntArray, diff: Int): Int = nums.count {
nums.contains(it)
&& nums.contains(it + diff)
&& nums.contains(it + diff + diff)
}
}
回到 leetcode 列表