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. IOC Unity

    1. 依赖倒置原则和IOC2. IOC(Inversion of Control)的好处3. 介绍和使用Unity依赖倒置原则(DIP):上层和下层之间,依赖抽象,而不依赖细节IOC 控制反转,把上端 ...

  2. textView的提醒文字

    如果我们想提交一些备注信息,会想到用textFiled和textView两种控件去实现 1.提醒文字是textFiled的特有属性,但是textFiled显示文本只有一行,不能实现我们输入较多文字的情 ...

  3. 移动端自适应:flexible.js可伸缩布局使用

    http://caibaojian.com/flexible-js.html 阿里团队开源的一个库.flexible.js,主要是实现在各种不同的移动端界面实现一稿搞定所有的设备兼容自适应问题. 实现 ...

  4. SFDC中的DEBUG

    SFDC的顾问初期,基本都是做一些配置的工作,权限,字段,工作流和审批流之类.那么在这些工作流或者审批流没有按照你预想的来运行而且你检查了多遍后没有找到问题所在的时候.你就需要DEBUG了. 做过开发 ...

  5. 数据存储_FMDB

    一.简单说明 1.什么是FMDB FMDB是iOS平台的SQLite数据库框架 FMDB以OC的方式封装了SQLite的C语言API 2.FMDB的优点 使用起来更加面向对象,省去了很多麻烦.冗余的C ...

  6. Linux下安装 MySQL

    Ubuntu环境 使用二进制安装包安装,相对简单绿色 1.到官网下载二进制压缩包http://dev.mysql.com/downloads/mysql/ 2.选择需要的版本 目前最新为5.7.之后选 ...

  7. Java 静态内部类与非静态内部类 学习记录.

    目的 为什么会有这篇文章呢,是因为我在学习各种框架的时候发现很多框架都用到了这些内部类的小技巧,虽然我平时写代码的时候基本不用,但是看别人代码的话至少要了解基本知识吧,另外到底内部类应该应用在哪些场合 ...

  8. 计算机常用dos命令

    一.简单的dos命令 win+R ------打开"运行"窗口 cmd ------回车进入"dos"命令窗口 ipconfig ------查看本机ip地址 ...

  9. 【Redis安装学习】

    1.Redis 中文官网地址:http://www.redis.net.cn/download/ 这里只是简单的安装了下.具体的官网有详细的介绍和安装:跳转 如何安装 下载,解压,编译: $ wget ...

  10. Lattice Reduction (LLL) 算法C代码实现

    废话不多说,大名鼎鼎的Lenstra-Lenstra-Lovasz(LLL) 算法.实现参考论文:Factoring Polynomials with Rational Coefficients, 作 ...