246. Strobogrammatic Number

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Write a function to determine if a number is strobogrammatic. The number is represented as a string.

For example, the numbers "69", "88", and "818" are all strobogrammatic.

思路: 兩邊到內(nèi)check是否為 00 11 88 69 96
Time Complexity: O(N) Space Complexity: O(1)

Solution Code:

public boolean isStrobogrammatic(String num) {
    for (int i=0, j=num.length()-1; i <= j; i++, j--)
        if (!"00 11 88 696".contains(num.charAt(i) + "" + num.charAt(j)))
            return false;
    return true;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,169評(píng)論 0 23
  • 【飛箝第五】 原文:(5.1)凡度權(quán)量能,所以征遠(yuǎn)來(lái)近。立勢(shì)而制事,必先察同異,別是非之語(yǔ)。見內(nèi)外之辭,知有無(wú)之?dāng)?shù)...
    馬新閱讀 631評(píng)論 0 49
  • 手機(jī)不知不覺偷走了我太多的時(shí)間。下班回家,悠閑得躺著,追會(huì)劇,玩會(huì)游戲。
    小加油白閱讀 130評(píng)論 0 0

友情鏈接更多精彩內(nèi)容