剑指offer
把字符串转换成整数
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 64M,其他语言128M
热度指数:458170
本题知识点:
字符串
数学
字符串
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数。 数值为0或者字符串不是一个合法的数值则返回0
输入描述:
输入一个字符串,包括数字字母符号,可以为空
返回值描述:
如果是合法的数值表达则返回该数字,否则返回0
示例1
输入
复制
"+2147483647"
"+2147483647"
返回值
复制
2147483647
2147483647
示例2
输入
复制
"1a33"
"1a33"
返回值
复制
0
0
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
public class Solution { public int StrToInt(String str) { } }
class Solution { public: int StrToInt(string str) { } };
# -*- coding:utf-8 -*- class Solution: def StrToInt(self, s): # write code here
class Solution { public int StrToInt(string str) { // write code here } }
function StrToInt(str) { // write code here } module.exports = { StrToInt : StrToInt };
function StrToInt(str) { // write code here }
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ func StrToInt( str string ) int { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param str string字符串 # @return int整型 # class Solution def StrToInt(str) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ def StrToInt(str: String): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ fun StrToInt(str: String): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ public int StrToInt (String str) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ export function StrToInt(str: string): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ func StrToInt ( _ str: String) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ pub fn StrToInt(&self, str: String) -> i32 { // write code here } }
"+2147483647"
2147483647
"1a33"
0