389. Find the Difference

原创 2016年08月28日 19:58:48

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.
	public char findTheDifference(String s, String t) {
		int[] res = new int[26];
		for (int i = 0; i < s.length(); i++) {
			res[s.charAt(i) - 'a']++;
		}
		for (int i = 0; i < t.length(); i++) {
			if (res[t.charAt(i) - 'a'] > 0)
				res[t.charAt(i)]--;
			else
				return t.charAt(i);
		}
		return (Character) null;
	}



版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

389. Find the Difference

原题链接: https://leetcode.com/problems/find-the-difference/ 题目: Given two strings s and t which cons...

LeetCode笔记:389. Find the Difference

在两个字符串中找出唯一多出的那个字母

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

LeetCode 389. Find the Difference

题意两个字符串s,t,都是小写字母,t由s中的字符和新增的一个字母随机排列组合而成,找出新增的字符!思路最直接的思路是HashMap,根据字符串s建立一个HashMap,key是字母,value是字母...

leetcode389. Find the Difference

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters.String t i...

leetcode算法——389. Find the Difference(基于JAVA)

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

389. Find the Difference [easy] (Python)

题目链接https://leetcode.com/problems/find-the-difference/题目原文 Given two strings s and t which consist...

【LeetCode】389 Find the Difference(java)

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

Tutorial: 389. Find the Difference

LeetCode算法题:389. Find the Difference的解法。

[LeetCode]389. Find the Difference(找不同)

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters. String t...

389. Find the Difference

389. Find the Difference1 题目Given two strings s and t which consist of only lowercase letters.String...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)