FED28. 获取字符串的长度
描述
如果第二个参数 bUnicode255For1 === true,则所有字符长度为 1示例1
输入:
'hello world, 牛客', false
输出:
17
HTML/CSS/JavaScript 解法, 执行用时: 869ms, 内存消耗: 77900KB, 提交时间: 2020-11-18
{"css":"","js":"function strLength(s, bUnicode255For1) {\n let len = s.length\n if(bUnicode255For1 !== true){\n for(let i in s){\n if(s.charCodeAt(i)>255)len++\n } \n }\n return len\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 870ms, 内存消耗: 77772KB, 提交时间: 2020-11-22
{"css":"","js":"function strLength(s, bUnicode255For1) {\n let length = s.length\n \n if(!bUnicode255For1){\n for(let i = 0,len = s.len;i<length;i++){\n if(s.charCodeAt(i)>255){\n length++\n }\n }\n }\n \n return length\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 870ms, 内存消耗: 77828KB, 提交时间: 2020-11-04
{"css":"","js":"function strLength(s,bUnicode255For1) {\n if(bUnicode255For1) return s.length\n else{\n var len = 0\n for (var l in s) {\n if(s.charCodeAt(l) > 255) \n len +=2\n else len++\n }\n return len\n }\n\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 870ms, 内存消耗: 77900KB, 提交时间: 2021-01-17
{"css":"","js":"function strLength(s, bUnicode255For1) {\n var length=s.length;\n if(!bUnicode255For1){\n for( var i in s){\n if(s.charCodeAt(i)>255) {\n length++;\n }\n }\n }\n return length;\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 873ms, 内存消耗: 77772KB, 提交时间: 2020-12-29
{"css":"","js":"function strLength(s, bUnicode255For1) {\n var a = s.length\n if(bUnicode255For1){\n return a\n }else{\n for(var i = 0; i < s.length; i++){\n if(s.charCodeAt(i)>255){\n a++\n }\n }\n return a;\n }\n}","html":"","libs":[]}