把字符串转换成整数
2023/2/11小于 1 分钟
把字符串转换成整数
题目链接
题目描述
刷题思路
代码实现
/**
* 【较难】把字符串转换成整数
*/
export function StrToInt(str) {
if (!str)
return 0
let bool = false
const firstLetter = str[0]
if (firstLetter === '-')
bool = true
if (firstLetter === '-' || firstLetter === '+')
str = str.substring(1)
const n = Number(str)
if (n === 0)
return 0
return bool ? -n : n
}
一些建议
更新日志
2024/7/29 15:43
查看所有更新日志
5a2b2
-于c0f2d
-于06596
-于9b9e4
-于b0275
-于5f1e1
-于02ab1
-于8de1a
-于d0347
-于74e84
-于ced18
-于a23ce
-于74aa9
-于3c22c
-于9bbe9
-于e4c74
-于