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. sql server中对xml进行操作

    一.前言 SQL Server 2005 引入了一种称为 XML 的本机数据类型.用户可以创建这样的表,它在关系列之外还有一个或多个 XML 类型的列:此外,还允许带有变量和参数.为了更好地支持 XM ...

  2. js原生dom方法总结

    1.document document方法getElementById (Node)返回指定节点的引用getElementsByTagName (NodeList)返回文档中所有匹配元素的集合quer ...

  3. 美团HD(2)-设置导航栏内容

    DJHomeViewController.m #import "DJHomeViewController.h" #import "DJConstantValue.h&qu ...

  4. Java 泛型 <? super T> 中 super 怎么 理解?与 extends 有何不同?

    看知乎:https://www.zhihu.com/question/20400700 了解的越多,就会发现,越多不了解.

  5. phpcms 添加memcache支持

    1,修改caches/configs/cache.php <?php return array ( 'file1' => array ( 'type' => 'file', 'deb ...

  6. Workflow 中做拒绝操作时强制输入拒绝信息

    在做AP发票审批驳回时,客户要求必须强制输入拒绝原因,代码如下: PROCEDURE Validate_Response ( Itemtype IN VARCHAR2, Itemkey IN VARC ...

  7. MPMoviePlayerViewController

    MPMoviePlayerViewController        注意:需要添加MediaPlayer.framework    带有视频播放器的控制器(能够播放mp3.mp4.avi.mov格式 ...

  8. UI第十七节——UIScrollView

    // 实例化一个ScrollView    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen main ...

  9. Windows 安装JRuby 生成 war 到 tomcat 运行

    Windows安装JRuby Rails 直接下载 JRuby,不装 Ruby. http://jruby.org/download 该安装包可以配好环境变量 %JRUBY_HOME% 等 安装 bu ...

  10. VB中PictureBox控件使用教程

    PictureBox对象可以说是任何对象的原始型态,它可以加载图片.显示文字.画图外,它还能与Frame对象一样,在自己本身里头加载其它的对象而自成一个小群组,用PictureBox可以仿真出任何对象 ...