原題:https://leetcode.com/problems...測(cè)試了1534236469這個(gè)數(shù)字,不通過,估計(jì)他認(rèn)為數(shù)字溢出了,但是在js中這個(gè)數(shù)字壓根就沒有溢出啊代碼:/**
* @param {number} x
* @return {number}
*/var reverse = function(x) { var s = x<0?x.toString().substring(1):x.toString(); var arr = s.split('');
arr.reverse();
s = arr.join('');
s = x<0?'-'+s:s;
s = Number(s); //console.log(s,s>Number.POSITIVE_INFINITY,s<Number.NEGATIVE_INFINITY);
return s>Number.POSITIVE_INFINITY||s<Number.NEGATIVE_INFINITY?0:s;
};
leetcode上的一個(gè)題目,數(shù)字溢出問題
天涯盡頭無女友
2018-09-15 14:10:33