将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数。 数值为 0 或者字符串不是一个合法的数值则返回 0 数据范围:字符串长度满足 进阶:空间复杂度 ,时间复杂度 注意: ①字符串中可能出现任意符号,出现除 +- 以外符号时直接输出 0 ②字符串中可能出现 +- 且仅可能出现在字符串首位。
输入描述:
输入一个字符串,包括数字字母符号,可以为空
输出描述:
如果是合法的数值表达则返回该数字,否则返回0
示例1
输入
"+2147483647"
输出
2147483647
示例2
输入
"1a33"
输出
0
加载中...
import java.util.*; 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 };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param str string字符串 # @return int整型 # class Solution: def StrToInt(self , str: str) -> int: # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 * @return int整型 */ func StrToInt( str string ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return int整型 */ int StrToInt(char* str ) { // 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