Given two strings s and t which consist of only lowercase letters.

String t is generated by random shuffling string s and then add one more letter at a random position.

Find the letter that was added in t.

Example:

Input:
s = "abcd"
t = "abcde" Output:
e Explanation:
'e' is the letter that was added.
 一开始想用hashtable 来着,提交了以后发现完全没有考虑重复字符的情况。。。。最后采用排序然后线性扫描。应该没有更简单的方法了吧
/**
* @param {string} s
* @param {string} t
* @return {character}
*/
var findTheDifference = function(s, t) {
var ss = s.split('').sort();
var st = t.split('').sort();
var i = 0;
while (1) {
if (st[i] !== ss[i]) return st[i];
i++;
}
};

[LeetCode] Find the Difference的更多相关文章

  1. LeetCode——Find the Difference

    LeetCode--Find the Difference Question Given two strings s and t which consist of only lowercase let ...

  2. [LeetCode] Minimum Time Difference 最短时间差

    Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...

  3. [LeetCode] Minimum Absolute Difference in BST 二叉搜索树的最小绝对差

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

  4. LeetCode Minimum Time Difference

    原题链接在这里:https://leetcode.com/problems/minimum-time-difference/description/ 题目: Given a list of 24-ho ...

  5. LeetCode Minimum Absolute Difference in BST

    原题链接在这里:https://leetcode.com/problems/minimum-absolute-difference-in-bst/#/description 题目: Given a b ...

  6. LeetCode 1026. Maximum Difference Between Node and Ancestor

    原题链接在这里:https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/ 题目: Given the ro ...

  7. [LeetCode] Find the Difference 寻找不同

    Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...

  8. LeetCode:Find the Difference_389

    LeetCode:Find the Difference [问题再现] Given two strings s and t which consist of only lowercase letter ...

  9. LeetCode 530. Minimum Absolute Difference in BST (二叉搜索树中最小绝对差)

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

随机推荐

  1. ASP.MVC 基于AuthorizeAttribute权限设计案例

    ASP.MVC上实现权限控制的方法很多,比如使用AuthorizeAttribute这个特性 1.创建自定义特性用于权限验证 public class AuthorizeDiy : Authorize ...

  2. 仿淘宝分页按钮效果简单美观易使用的JS分页控件

    分页按钮思想:  1.少于9页,全部显示  2.大于9页,1.2页显示,中间页码当前页为中心,前后各留两个页码  附件中有完整例子的压缩包下载.已更新到最新版本  先看效果图:  01输入框焦点效果  ...

  3. Android五岁了

    今日(2013-9-24),谷歌开源系统Android迎来了它5岁的生日. 时间过得真快啊!当时的android并不被人看好,而现在的android已经成为了全球最大的智能手机操作系统.而现在的诺基亚 ...

  4. java从基础知识(七)java集合

    一.集合类介绍 1.List(元素有放入顺序,可重复) 1.1.List的实现 1.1.1.ArrayList ArrayList就是动态数组(需要连续的存储空间),用MSDN中的说法,就是Array ...

  5. centos7 打开mysql 3306端口并 设置外部访问

    mysql安装后默认是localhost访问,如果需要外部访问可以设置一个新的账号把host改为%,意味着所有ip均可以访问 grant all privileges on *.* to 'outUs ...

  6. Jquery制作--焦点图左右轮播

    公司项目经常用到轮播焦点图,于是自己写了一个纯jq形式的横向轮播焦点图,可点击小圆点或者左右按钮进行切换,属于定宽类型.改成自适应宽度的也不难,将css里面的bannerCon宽度改为百分比,再在js ...

  7. 关于linux下system()函数的总结

    导读 曾经的曾经,被system()函数折磨过,之所以这样,是因为对system()函数了解不够深入.这里必须要搞懂system()函数,因为有时你不得不面对它. 先来看一下system()函数的简单 ...

  8. Linux kernel 文件夹说明

    Linux 内核代码的目录结构 arch: 包含和硬件体系相关的的代码,每种硬件平台占一个相应的目录,如i386,arm, arm64, powerpc,mips等. block: 块设备驱动程序I/ ...

  9. Android下LayoutInflater的使用

    在我们想XML布局文件转换为View对象的时候.我们都会使用LayoutInflate对象.顾名思义咋一眼就能看出来他是布局填充器.那么接下来看看LayoutInfalte的使用 总体分为 Layou ...

  10. js 数组,字符串,json互相转换

    数组转字符串 var arr = [1,2,3,4,'巴德','merge']; var str = arr.join(','); console.log(str); // 1,2,3,4,巴德,me ...