首页 > 其他 > 详细

Leetcode 246: Strobogrammatic Number

时间:2017-12-18 13:21:33      阅读:196      评论:0      收藏:0      [点我收藏+]

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.

 

 1 public class Solution {
 2     public bool IsStrobogrammatic(string num) {
 3         if (num == null || num.Length == 0) return true;
 4         
 5         int i = 0, j = num.Length - 1;
 6         
 7         while (i <= j)
 8         {
 9             if ((num[i] == 6 && num[j] == 9) || (num[i] == 9 && num[j] == 6) || (num[i] == 8 && num[j] == 8) || (num[i] == 0 && num[j] == 0) || (num[i] == 1 && num[j] == 1))
10             {
11                 i++;
12                 j--;
13             }
14             else
15             {
16                 return false;
17             }
18         }
19         
20         return true;
21     }
22 }

 

Leetcode 246: Strobogrammatic Number

原文:http://www.cnblogs.com/liangmou/p/8056940.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!