该系列共三道题,Company Tag只有一个Google
,那就必须要做了。
第一题题目内容
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,那翻过来还是1,0和8都是,有区别的就是6和9,因为上下颠倒很有可能导致性别的不同,所以左边是6的话,对称位置必须是9。所以这题先建立一个对应的map,然后扫一遍字符串就可以了。
code
复杂度分析
第二题题目内容
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.
For example,
Given n = 2, return ["11","69","88","96"].
解决思路
一看关键词find/return all
#$%^,通常都是DFS,深搜一遍,挖地三尺,雁过拔毛。
code
复杂度分析
第三题题目内容
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 of low <= num <= high.
For example,
Given low = "50", high = "100", return 3. Because 69, 88, and 96 are three strobogrammatic numbers.
Note:
Because the range might be a large number, the low and high numbers are represented as string.