467. [leetcode] Unique Substrings in Wraparound String
问题描述
Implement atoi to convert a string to an integer.
Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.
Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front.
Update (2015-02-10):
The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button to reset your code definition.
原题链接:https://leetcode.com/problems/string-to-integer-atoi/
Analysis
public int myAtoi(String str) {
if(str == null || str.length() == 0){
return 0;
}
char[] chs = str.trim().toCharArray();
int isPositive = 1, index = 0;
if(chs[0] == '-'){
isPositive = -1;
index = 1;
}
if(chs[0] == '+'){
isPositive = 1;
index = 1;
}
long res = 0;
for(; index < chs.length; index++){
if(chs[index] < '0' || chs[index] > '9' ){
return (int)res;
}
res = res * 10 + isPositive * (chs[index] - '0');
if(res > Integer.MAX_VALUE){
return Integer.MAX_VALUE;
}
if(res < Integer.MIN_VALUE){
return Integer.MIN_VALUE;
}
}
return (int)res;
}
467. [leetcode] Unique Substrings in Wraparound String的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 【LeetCode】467. Unique Substrings in Wraparound String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/unique-s ...
- LeetCode 467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 【LeetCode】467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- [Swift]LeetCode467. 环绕字符串中唯一的子字符串 | Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 动态规划-独特的子字符串存在于Wraparound String总个数 Unique Substrings in Wraparound String
2018-09-01 22:50:59 问题描述: 问题求解: 如果单纯的遍历判断,那么如何去重保证unique是一个很困难的事情,事实上最初我就困在了这个点上. 后来发现是一个动态规划的问题,可以将 ...
- 467 Unique Substrings in Wraparound String 封装字符串中的独特子字符串
详见:https://leetcode.com/problems/unique-substrings-in-wraparound-string/description/ C++: class Solu ...
随机推荐
- 【Web】一个非常简单的移动web消息框
适用:h5+jquery,移动网页最佳 最近在写个简单的公众号页面,前端验证时有些信息要提示,很简单的需求实在不想找啥现成的轮子,又不至于用alert这么粗暴,遂写了个非常简单的消息框,效果如图: 特 ...
- XML解析的四种方法 建议使用demo4j解析 测试可以用
https://www.cnblogs.com/longqingyang/p/5577937.html 4.DOM4J解析 特征: 1.JDOM的一种智能分支,它合并了许多超出基本XML文档表示的功 ...
- Windows下SVN命令行工具使用详解
根据我的记忆,似乎Windows 7下自自带一个svn命令行工具.如果你的机器没有,不必担心.你可以从http://subversion.tigris.org获 取subversion for win ...
- Android 不规则图像填充 小玩着色游戏
转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/45788433: 本文出自:[张鸿洋的博客] 一.概述 近期群里偶然看到一哥们在 ...
- Javascript 进阶 面向对象编程 继承的一个例子
Javascript的难点就是面向对象编程,上一篇介绍了Javascript的两种继承方式:Javascript 进阶 继承,这篇使用一个例子来展示js如何面向对象编程,以及如何基于类实现继承. 1. ...
- WIN10怎么安装SQL server2000数据库
怎样在win10下安装sql2000数据库 1.安装之前先确认自己的Windows10是64位的还是32位的 2.替换对应的系统文件SQLUNIRL.dll 此时你可能会遇到,没有权限替换文件或重命名 ...
- Django中模板过滤器总结
一.形式:小写: {{ name | lower }} 二.串联:先转义文本到HTML,再转换每行到 <p> 标签: {{ my_text|escape|linebreaks } 三.过滤 ...
- 插入排序算法java
转自https://blog.csdn.net/jianyuerensheng/article/details/51254415 1.基本思想 直接插入排序的基本操作是将一个记录插入到已经排好的有序表 ...
- 用Axure进行原型设计
用Axure进行原型设计 看这个视频 http://www.iqiyi.com/playlist409963402.html
- java.lang.IllegalArgumentException异常 配置文件的问题
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Student is ...