Leetcode 246: Strobogrammatic Number

Posted Keep walking

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 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.

 

 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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode笔记:Weekly Contest 246 比赛记录

《LeetCode之每日一题》:246.分割回文串

LeetCode 剑指 Offer 38. 字符串的排列 / 31. 下一个排列 / 第 246 场周赛

LeetCode算法题-Find Mode in Binary Search Tree(Java实现)

246.Strobogrammatic Number

053第246题