[leetcode]389. Find the Difference -- JavaScript 代码
来源:互联网 发布:caxa数控车编程教程 编辑:程序博客网 时间:2024/05/16 07:17
/** * @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。
0 0
- [leetcode]389. Find the Difference -- JavaScript 代码
- 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
- LeetCode 389. Find the Difference
- LeetCode 389. Find the Difference
- leetcode 389. Find the Difference
- 389.[LeetCode]Find the Difference
- 【LeetCode】 389. Find the Difference
- [LeetCode]389. Find the Difference
- leetcode-389. Find the Difference
- Leetcode 389. Find the Difference
- POJ 3045(递推找规律)
- HTML5之SVG 2D入门7 - 重用与引用
- iOS-判断相册,相机,定位权限是否打开
- 浅谈java反射
- CAN总线开发实例
- [leetcode]389. Find the Difference -- JavaScript 代码
- oracle服务器和客户端字符集的查看和修改
- java web的验证码编写和运用
- 最全的常用正则表达式大全
- spring注解
- Java 监听器
- 阿里云消息队列的实践应用
- 判断字符串是否是邮箱或者手机号码格式
- 设置导航栏背景色和view背景色