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.

思路: 两边到内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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,891评论 0 23
  • 【飞箝第五】 原文:(5.1)凡度权量能,所以征远来近。立势而制事,必先察同异,别是非之语。见内外之辞,知有无之数...
    马新阅读 613评论 0 49
  • 手机不知不觉偷走了我太多的时间。下班回家,悠闲得躺着,追会剧,玩会游戏。
    小加油白阅读 118评论 0 0