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. Thymeleaf

    1.在html顶部添加 <html xmlns:th="http://www.thymeleaf.org"> 2.url表达式 @{...} <link rel= ...

  2. thinkphp使用ajax

    thinkphp使用ajax和之前使用ajax的方法一样,不同点在于之前的ajax中的url指向了一个页面,而thinkphp里面的url需要指向一个操作方法. 一.thinkphp使用ajax返回数 ...

  3. 浅谈Android样式开发之layer-list

    引言 在开发某些有层叠效果App时,我们第一个想到的就是让UI进行切图.下面我们来这样的一个例子.如图所示: 上图Tab的背景效果,和带阴影的圆角矩形,是怎么实现的呢?大部分的人会让美工切图,用点九图 ...

  4. Codeforces Round 319 # div.1 & 2 解题报告

    Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...

  5. window 使用vagrant搭建开发开发环境

    # -*- mode: ruby -*-# vi: set ft=ruby : # All Vagrant configuration is done below. The "2" ...

  6. JQuery radio(单选按钮)操作方法汇总

    这篇文章主要介绍了JQuery radio(单选按钮)操作方法汇总,本文讲解了获取选中值.设置选中值.根据Value值设置选中.删除Radio.遍历等内容,需要的朋友可以参考下   随着Jquery的 ...

  7. DHCP

    安装 yum install -y dhcp 配置文件 默认配置为/etc/dhcpd.conf [root@samba ~]# [root@samba ~]# rpm -ql dhcp | grep ...

  8. Python绘图

    1.二维绘图 a. 一维数据集 用 Numpy ndarray 作为数据传入 ply 1. import numpy as np import matplotlib as mpl import mat ...

  9. JAVA输入输出流

    概述: 各种流类型(类和抽象类)都位于位于java.io包中,各种流都分别继承一下四种抽象流中的一种: 类型 字节流 字符流 输入流 InputStream Reader 输出流 OutputStre ...

  10. runtime理论知识

    http://southpeak.github.io/2014/10/25/objective-c-runtime-1/ 转载http://www.jianshu.com/p/6b905584f536 ...