[leetcode]389. Find the Difference -- JavaScript 代码
2016-08-30 16:45
726 查看
/** * @param {string} s * @param {string} t * @return {character} */ var findTheDifference = function(s, t) { var tlen = t.length; var slen = s.length; var ret = 0; for(var i=0;i<slen;i++){ ret ^= s.charCodeAt(i); } for(i=0;i<tlen;i++){ ret ^= t.charCodeAt(i); } return String.fromCharCode(ret); };
使用位运算应该是最快的方法:数字自己和自己异或(^)等于0。
使用了JS的函数s.charCodeAt和String.fromCharCode。
相关文章推荐
- leetcode 389. Find the Difference 解题报告
- Leetcode 389. Find the Difference
- leetcode之389. Find the Difference(C++解法)
- Leetcode 389 Find the Difference
- 【leetcode】389. Find the Difference
- Leetcode 389. Find the Difference (Easy) (cpp)
- LeetCode 389:Find the Difference
- LeetCode 389: Find the Difference 题解
- LeetCode(389) Find the Difference
- LeetCode 389. Find the Difference
- Leetcode 389 Find the Difference
- Leetcode 389. Find the Difference 找不同 解题报告
- LeetCode—389. Find the Difference
- leetcode 389. Find the Difference 牛人用异或 或者 求和 解决,很简单。
- 【LeetCode-389】Find the Difference(C++)
- LeetCode[389]Find the Difference
- [leetcode] 389. Find the Difference 解题报告
- leetcode 389. Find the Difference
- 【leetcode】389. Find the Difference【E】
- LeetCode 389. Find the Difference