Kotlin Leetcode - 3280. Convert Date to Binary
題目連接:https://leetcode.com/problems/convert-date-to-binary/
class Solution {
    fun convertDateToBinary(date: String): String {
        
    }
}
解題思路
這一題考的是字串處理的邏輯
我們可以用 split() 將日期拆解出數字
然後用 toInt().toString(2)  轉換成二進位表示
最後用 joinToString() 合併為一個字串
Kotlin 參考解答
點擊展開解答
class Solution {
    fun convertDateToBinary(date: String) =
        date.split('-')
            .joinToString("-") {
                it.toInt().toString(2)
            }
}
- 回到 leetcode 列表