找不同

作者: _William_Zhang | 来源:发表于2019-02-19 11:07 被阅读0次

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.

输入给两个只包含小写字母的字符串 S 和 T.

字符串 T 是在字符串 S 基础上添加一个小写字母, 然后随机打乱之后生成.

请找出那个被加入的小写字母.

示例:

Input:
s = "abcd"
t = "abcde"

Output:
e

Explanation:
'e' is the letter that was added.

在线测试网站: https://leetcode.com/problems/find-the-difference/description

class Solution {
    public char findTheDifference(String s, String t) {
        int ret = 0;
        for(int i = 0; i < s.length(); i++) {
            ret -= (int) s.charAt(i);
        }
        for(int i = 0; i < t.length(); i++) {
            ret += (int) t.charAt(i);
        }
        return (char) ret;
    }
}

相关文章

  • 找不同

  • 找不同

    每一天生命充满了奇迹,每一个瞬间是那样细腻而温柔,充满了灵动,我的每一个细胞在都在和每一个遇见活泼的互动着,每一时...

  • 找不同

  • 找不同

    找不同 文/若素 左边 右边 到处都是生活 孩子张着嘴等待父亲的筷子 母亲看着吃得很香的女儿眯着眼睛 在每一个节日...

  • 找不同

    百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百百白百百百百百百百百百百百百百百百百...

  • 找不同

    你是首先希望你的国家越来越好,还是首先希望这个世界越来越好? 你是首先希望你自己越来越好,还是首先希望你的国家越来越好?

  • 找不同

    以下是儿子的解答 第一组:第四个不一样,因为它是吃的,其他的都是比赛用的,我说是体育用品,他非要说是比赛用的,没...

  • 找不同

    房间找不同

  • 找不同

    房间找不同

  • 找不同

    Given two strings s and t which consist of only lowercase...

网友评论

      本文标题:找不同

      本文链接:https://www.haomeiwen.com/subject/dkrxyqtx.html