[LeetCode] Find the Difference
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.
/**
* @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的更多相关文章
- LeetCode——Find the Difference
LeetCode--Find the Difference Question Given two strings s and t which consist of only lowercase let ...
- [LeetCode] Minimum Time Difference 最短时间差
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...
- [LeetCode] Minimum Absolute Difference in BST 二叉搜索树的最小绝对差
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- LeetCode Minimum Time Difference
原题链接在这里:https://leetcode.com/problems/minimum-time-difference/description/ 题目: Given a list of 24-ho ...
- LeetCode Minimum Absolute Difference in BST
原题链接在这里:https://leetcode.com/problems/minimum-absolute-difference-in-bst/#/description 题目: Given a b ...
- LeetCode 1026. Maximum Difference Between Node and Ancestor
原题链接在这里:https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/ 题目: Given the ro ...
- [LeetCode] Find the Difference 寻找不同
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- LeetCode:Find the Difference_389
LeetCode:Find the Difference [问题再现] Given two strings s and t which consist of only lowercase letter ...
- LeetCode 530. Minimum Absolute Difference in BST (二叉搜索树中最小绝对差)
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
随机推荐
- IntelliJ IDEA 15,16 win 7 64位安装包以及注册码 百度云盘
不知道发出来,有用没有,要是官网下载不了的话,可以用我的这个哦,虽然不是最新的. ideaIU-162.1447.21 ideaIU-15.0.2 win7 64系统的安装包 链接:http://p ...
- oracle 按时间段统计15分钟内的数据
string sql = "select to_char(StartTime, 'yyyy')||'-'|| to_char(StartTime, 'mm')||'-'|| to_char( ...
- 使用vlc播放器播放rtsp流视频
可参考: 使用vlc播放器做rtsp服务器 web网页中使用vlc插件播放相机rtsp流视频 使用vlc进行二次开发做自己的播放器 首先需要安装vlc播放器,下载及安装步骤略 使用vlc播放器播放rt ...
- 查看IO负载
负载(load)是linux机器的一个重要指标,直观了反应了机器当前的状态.如果机器负载过高,那么对机器的操作将难以进行. Linux的负载高,主要是由于CPU使用.内存使用.IO消耗三部分构成.任意 ...
- [Java] Maven 建立 Spring MVC 工程
GIT: https://github.com/yangyxd/Maven.SpringMVC.Web 1. 建立 WebApp 工程 下一步: 下一步: 选择 maven-archetype-web ...
- 在QtCreator中使用doxygen
接触Doxygen后,认识到其强大之处,一口气将之前的烂代码重构了一遍,所有的文件头,函数注释等等都是手动添加注释.在keil中可以看到其对JavaDoc风格的注释有高亮,非常好看.但是keil这个I ...
- 使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样
使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样openid生成是根据应用的appid和QQ号的一些信息加密生成,对于一个appid和QQ号来说,openid是唯一的 ...
- 利用exp/imp备份恢复数据库实例
用exp/imp备份数据库: Oracle数据导入导出imp/exp功能:Oracle数据导入导出imp/exp就相当与oracle数据还原与备份. 大多情况都可以用Oracle数据导入导出完成数据的 ...
- Code Snippets 代码片段
Code Snippets 代码片段 1.Title : 代码片段的标题 2.Summary : 代码片段的描述文字 3.Platform : 可以使用代码片段的平台,有IOS/OS X/ ...
- PHP中::、->、self、$this操作符的区别
在访问PHP类中的成员变量或方法时,如果被引用的变量或者方法被声明成const(定义常量)或者static(声明静态),那么就必须使用操作符::,反之如果被引用的变量或者方法没有被声明成const或者 ...