389. Find the Difference

原创 2016年08月29日 15:37:03

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.

难度:EASY
代码:

public class Solution {
    public char findTheDifference(String s, String t) {
        int[] counts=new int[26];
        int[] countt=new int[26];
        for (int i=0;i<s.length();i++){
            counts[s.charAt(i)-'a']++;
        }
        for (int i=0;i<t.length();i++){
            countt[t.charAt(i)-'a']++;
        }
        for (int j=0;j<26;j++){
            if (counts[j]!=countt[j]){
                return (char) (j+'a');
            }
        }
        return ' ';
    }
}

相关文章推荐

LeetCode笔记:389. Find the Difference

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

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 ...
  • styshoo
  • styshoo
  • 2016年09月29日 23:46
  • 482

Tutorial: 389. Find the Difference

LeetCode算法题:389. Find the Difference的解法。
  • atmiao
  • atmiao
  • 2016年12月26日 22:18
  • 127

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

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

[LeetCode]242.Valid Anagram&383. Ransom Note&389. Find the Difference

242.Valid Anagram 383. Ransom Note 389. Find the Difference

389. Find the Difference

Given two strings s and t which consist of only lowercase letters.String t is generated by random sh...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:389. Find the Difference
举报原因:
原因补充:

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