Open jajaplus opened 5 years ago
https://leetcode-cn.com/problems/string-to-integer-atoi/submissions/
/** * @param {string} str * @return {number} */ var myAtoi = function(str) { let num = "" let isValidNum = false for(let strIndex =0; strIndex<str.length;strIndex++){ if(str[strIndex]!==' '&&!num){ if(isNaN(str[strIndex])&&!['-','+'].includes(str[strIndex])){ break } isValidNum = true }else if((str[strIndex]===' '||isNaN(str[strIndex]))&&num){ isValidNum = false break } if(isValidNum){ num = num + str[strIndex] } } if(num<Math.pow(2,31)*-1){ num = Math.pow(2,31)*-1 }else if(num>(Math.pow(2,31)-1)){ num = Math.pow(2,31)-1 } return num&&!isNaN(num)?parseInt(num):0 };``` ## 阅读(linting作用和安装) https://www.freecodecamp.org/news/what-is-linting-and-how-can-it-save-you-time/ ## 正则表达式 目的:在字符串中过滤或则替换我们想要的特定字符串 组成:普通字符和元字符 参数:g:查找所有符合匹配的字符 i:忽略大小写 m:允许多行匹配,^、$可以设多个匹配各个行的开头和结尾 ## 分享(敏捷开发) https://my.oschina.net/guoenzhou/blog/791566
算法
https://leetcode-cn.com/problems/string-to-integer-atoi/submissions/