成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

[LeetCode] 246. Strobogrammatic Number

whatsns / 1352人閱讀

Problem

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.

Example 1:

Input: "69"
Output: true
Example 2:

Input: "88"
Output: true
Example 3:

Input: "962"
Output: false

Solution
class Solution {
    public boolean isStrobogrammatic(String s) {
        //69, 88, 00, 11, 6969, 698869, 69869, 6908069, 886988
        Map map = new HashMap<>();
        map.put("6", "9");
        map.put("9", "6");
        map.put("0", "0");
        map.put("1", "1");
        map.put("8", "8");
        int i = 0, j = s.length()-1;
        while (i <= j) {
            if (!map.containsKey(s.charAt(i))) return false;
            if (map.get(s.charAt(i++)) != s.charAt(j--)) return false;
        }
        return true;
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/77259.html

相關(guān)文章

  • 246. 247. 248. Strobogrammatic Number I II II

    摘要:題目解答題目解答先考慮最底層的兩種情況,當(dāng)和當(dāng)?shù)臅r(shí)候,就是最中間的數(shù)為空還是存在唯一的一個(gè)數(shù)。然后我們?cè)谶@個(gè)基礎(chǔ)上,用循環(huán)兩個(gè)數(shù)兩個(gè)數(shù)地一起向外擴(kuò)張。擴(kuò)張后的結(jié)果存在里,作為再服務(wù)于上一層的擴(kuò)張,得到最終結(jié)果。 246.Strobogrammatic NumberI題目:A strobogrammatic number is a number that looks the same w...

    Fundebug 評(píng)論0 收藏0
  • [Leetcode] Strobogrammatic Number 對(duì)稱(chēng)數(shù)

    摘要:比如,先判斷和是有映射的,然后和自己又是映射,所以是對(duì)稱(chēng)數(shù)。這樣每次從中間插入兩個(gè)對(duì)稱(chēng)的字符,之前插入的就被擠到兩邊去了。只插入一個(gè)字符時(shí)不能插入和插入字符和它的對(duì)應(yīng)字符 Strobogrammatic Number I A strobogrammatic number is a number that looks the same when rotated 180 degrees ...

    wendux 評(píng)論0 收藏0
  • [LeetCode] 247. Strobogrammatic Number II

    Problem A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Find all strobogrammatic numbers that are of length = n. Example: Input: n = 2Output...

    GHOST_349178 評(píng)論0 收藏0
  • [LeetCode] 248. Strobogrammatic Number III

    Problem A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to count the total strobogrammatic numbers that exist in the range o...

    yzd 評(píng)論0 收藏0
  • 247. Strobogrammatic Number II

    摘要:題目鏈接這題和都可以做,一種思路就是從中間開(kāi)始往兩邊延伸,每次有種可能性和,其中開(kāi)頭處不能是??梢约踊蛘哂脙?yōu)化。 247. Strobogrammatic Number II 題目鏈接:https://leetcode.com/problems... 這題recursion和iteration都可以做,一種思路就是從中間開(kāi)始往兩邊延伸,每次c[i-k], c[i+k]有5種可能性: (...

    cnTomato 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<