Strobogrammatic Number – LeetCode 246
Problem
Description
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.
Answer
Original
Code
1 | class Solution { |
思路
从头尾两个方向遍历,对可以形成对称结构的字符对应进行查找,依次判断即可。时间复杂度$O(n)$,空间复杂度$O(1)$。
Better
思路
还没看到更好的思路。