246. Strobogrammatic Number 上下对称的数字
2024-09-02 14:07:49
[抄题]:
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.
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
[奇葩corner case]:
[思维问题]:
class Solution {
public boolean isStrobogrammatic(String num) {
//cc
if (num == null || num.length() == 0) {
return true;
} //for loop
for (int i = 0, j = num.length() - 1; i <= j ; i++, j --) {
if (!"11 00 88 69 96".contains(num.charAt(i) + "" + num.charAt(j))) return false;
} return true;
}
}
不知道对称性怎么处理:两个指针啊!
[一句话思路]:
抽出来之后看字符串中是否互相包含
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
判断字符串对称 用对撞型指针
[复杂度]:Time complexity: O(n) Space complexity: O(1)
[英文数据结构或算法,为什么不用别的数据结构或算法]:
[关键模板化代码]:
[其他解法]:
[Follow Up]:
247. Strobogrammatic Number II 找出所有两位的:递归,好吧
[LC给出的题目变变变]:
[代码风格] :
最新文章
- 亚马逊S3下载上传文件
- Asp.net MVC Comet推送
- PHP用curl伪造IP和来源
- (转载)robots.txt写法大全和robots.txt语法的作用
- nullable,nonnull, null_resettable以及_Null_unspecified的区别和使用
- Python Charts库的使用
- 设计模式之美:Extension Object(扩展对象)
- Installation of Theano on Windows
- python 练习 17
- 用Spring3编写第一个HelloWorld项目
- ERP实施顾问是干什么的?
- js中常用的操作字符串的方法大全
- goDaddy SSL证书 Nginx配置全流程 (转)
- 业余草基于JAVA的模块化开发框架JarsLink
- appserver WildFly 8.1 / jboss debug / jboss rmi
- quratz启动流程
- linux创建快捷方式ln命令
- Java的三种代理模式:静态代理/JDK动态代理/Cglib动态代理
- centos7 虚拟机安装 以后不能联网问题
- Node.js实战(三)之第一个Web服务器
热门文章
- Dreamweaver_CS6安装与破解
- mysql8之与标准sql的区别
- 微博6月底升级后 报 10017/2/statuses/share.json或者10014/2/statuses/share.json错误
- 在oracle里,如何取得本周、本月、本季度、本年度的第一天和最后一天的时间
- haproxy中两个常用的宏
- (转)Socket开发时,Available为0,实际还有数据的问题
- Intellij idea run dashboard面板
- 数据分析与处理之二(Leveldb 实现原理)
- C# 32位程序访问64位注册表
- 路边拾遗之其他模块(struct/csv/xlwt/smtp)