We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接:https://leetcode-cn.com/problems/find-the-difference/
解题思路:
String.fromCharCode
charCodeAt
codePointAt
String.fromCodePoint
/** * @param {string} s * @param {string} t * @return {character} */ var findTheDifference = function (s, t) { let code = 0; // 保存ASCII码的值 // 遍历将t中所有字符ASCII码的值求和 for (const char of t) { code += char.charCodeAt(0); } // 因为t比s多一个字符,因此只要将t中字符ASCII码减去s的ASCII码,剩下的一个就是被添加的字符 for (const char of s) { code -= char.charCodeAt(0); } // 将ASCII码转换成字符串,就得到了结果 return String.fromCharCode(code); };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接:https://leetcode-cn.com/problems/find-the-difference/
解题思路:
String.fromCharCode
将ASCII码转换成字符串即可。charCodeAt
和String.fromCharCode
替换成codePointAt
和String.fromCodePoint
也是同样效果。The text was updated successfully, but these errors were encountered: