题目:8. 字符串转换整数 (atoi)
代码:
var myAtoi = function(str) {
const result = str.trim().match(/^(-|\+)?\d+/g);
return result
? Math.max(Math.min(Number(result[0]), 2 ** 31 - 1), -(2 ** 31))
: 0;
};
题目:8. 字符串转换整数 (atoi)
代码:
var myAtoi = function(str) {
const result = str.trim().match(/^(-|\+)?\d+/g);
return result
? Math.max(Math.min(Number(result[0]), 2 ** 31 - 1), -(2 ** 31))
: 0;
};