关闭

leetcode389

标签: leetcodeASCII
115人阅读 评论(0) 收藏 举报
分类:

1、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.

class Solution {
public:
    char findTheDifference(string s, string t) {
        int sum=0,sum1=0;
        for(int i=0;i<s.length();i++){
            sum=sum+s[i];
        }
        for(int i=0;i<t.length();i++){
            sum1=sum1+t[i];
        }
        return sum1-sum;
    }
};

这个题类似与上一道题,把字母的问题转化成ASCII码加减~~简单高效~

0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

LeetCode笔记:389. Find the Difference

在两个字符串中找出唯一多出的那个字母
  • Cloudox_
  • Cloudox_
  • 2016-09-08 15:45
  • 1693

LeetCode 389. Find the Difference

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

leetcode389. Find the Difference

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters.String t i...
  • rxt2012kc
  • rxt2012kc
  • 2017-06-13 20:48
  • 129

leetcode_389

找出两个字符串的不同
  • u014248127
  • u014248127
  • 2016-11-13 00:10
  • 115

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...
  • micky_Kiko
  • micky_Kiko
  • 2016-09-06 11:48
  • 1246

【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
  • 525

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

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters. String t...
  • whl_program
  • whl_program
  • 2017-03-12 18:15
  • 154

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

242.Valid Anagram 383. Ransom Note 389. Find the Difference
  • starrrr2
  • starrrr2
  • 2016-09-16 20:28
  • 111

【Leetcode】389. Find the Difference

方法一: 思路: 利用一个HashMap,先统计s字符串中每个字符出现的次数,然后遍历t字符串,若该字符未包含在HashMap中或出现次数等于0,立即返回该字符,否则,该字符出现的次数减一。 pub...
  • zhouziyu2011
  • zhouziyu2011
  • 2017-03-04 09:00
  • 146

389.Valid Sudoku-判断数独是否合法(容易题)

判断数独是否合法 题目请判定一个数独是否有效。 该数独可能只填充了部分数字,其中缺少的数字用 . 表示。注意事项 一个合法的数独(仅部分填充)并不一定是可解的。我们仅需使填充的空格有效即可。 说...
  • Tri_Color_Flag
  • Tri_Color_Flag
  • 2016-09-13 23:00
  • 197
    个人资料
    • 访问:8432次
    • 积分:659
    • 等级:
    • 排名:千里之外
    • 原创:59篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条