给定两个字符串 s 和 t,它们只包含小写字母。

字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。

请找出在 t 中被添加的字母。

示例:

输入: s = "abcd" t = "abcde" 输出: e 解释: 'e' 是那个被添加的字母。

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

LeetCode389Find the Difference找不同的更多相关文章

  1. 389 Find the Difference 找不同

    给定两个字符串 s 和 t,它们只包含小写字母.字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母.请找出在 t 中被添加的字母.示例:输入:s = "abcd"t = ...

  2. 389. Find the Difference 找出两个字符串中多余的一个字符

    [抄题]: Given two strings s and t which consist of only lowercase letters. String t is generated by ra ...

  3. C++ 迭代器容器学习

    set的一个用法 . difference找差集 union合并set intersection找到交集 #include<iostream> #include<string> ...

  4. LeetCode-day05

    45. Single Number 在个数都为2的数组中找到个数为1的数 46. Missing Number 在数组中找到从0到n缺失的数字 47. Find the Difference 找两个字 ...

  5. day004-python运算符与基本数据类型

    一.运算符1.算术运算符:主要用于两个对象算数计算(加减乘除等运算)运算符: +:两个对象相加 -:得到负数或是一个数减去另一个数 *:两个数相乘或是返回一个被重复若干次的字符串 /:x除以y %:返 ...

  6. Python【集合】、【函数】、【三目运算】、【lambda】、【文件操作】

    set集合: •集合的创建; set_1 = set() #方法一 set_1 = {''} #方法二 •set是无序,不重复的集合; set_1 = {'k1','k2','k3'} set_1.a ...

  7. [Swift]LeetCode389. 找不同 | Find the Difference

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

  8. Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference

    最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...

  9. Distribute numbers to two “containers” and minimize their difference of sum

    it can be solved by Dynamical Programming.Here are some useful link: Tutorial and Code: http://www.c ...

随机推荐

  1. 在windows中用cmd命令执行python无限循环程序如何停止

    在windows中用cmd命令测试python带有无限循环的程序,当想要终止时, 即linux中的Ctrl + D 相似的功能时可以用 Ctrl + Pause Break, 有FN功能键的可能要使用 ...

  2. 【BZOJ4805】欧拉函数求和

    题面 Description 给出一个数字N,求\(\sum\limits_{i=1}^n\varphi(i)\)i,1<=i<=N Input 正整数N.N<=2*10^9 Out ...

  3. 容斥原理——hdu3208

    和hdu2204有点像 这题要特别注意精度问题,如pow的精度需要自己搞一下,然后最大的longlong可以设为1<<31 /* 只要求[1,n]范围内的sum即可 那么先枚举幂次k[1, ...

  4. 如何做一个标记为安全的ACTIVEX控件

    1.添加辅助函数控件的基本结构中含有xxApp,xxCtrl,xxPropPage三个类.找到xxApp的头文件,添加三个辅助函数.// Helper functionto create a comp ...

  5. C++ 判断是否为邮箱格式

    总结了一下合法的email地址格式如下: 1. 首字符必须用字母,而且其它的字符只能用26个大小写字母.0~9及_-.@符号 2. 必须包含一个并且只有一个符号“@” 3. @后必须包含至少一个至多三 ...

  6. springboot与热部署

    在开发中我们修改一个Java文件后想看到效果不得不重启应用,这导致大量时间花费,我们希望不重启应用的情况下,程序可以自动部署(热部署).有以下四种情况,如何能实现热部署. 1.模板引擎: 在Sprin ...

  7. Vue数据双向绑定(面试必备) 极简版

    我又来吹牛逼了,这次我们简单说一下vue的数据双向绑定,我们这次不背题,而是要你理解这个流程,保证读完就懂,逢人能讲,面试必过,如果没做到,请再来看一遍,走起: 介绍双向数据之前,我们先解释几个名词: ...

  8. C++ 函数模板&类模板详解

    在 C++ 中,模板分为函数模板和类模板两种.函数模板是用于生成函数的,类模板则是用于生成类的. 函数模板&模板函数     类模板&模板类  必须区分概念 函数模板是模板,模板函数时 ...

  9. 赛后总结——codeforces round 551 div2

    传送门:QAQQAQ 好歹这次比赛打进前1000了...但第一题WA掉也是醉了... 每次比赛刚开始都是太心急,第一题写的特别快,不经过任何检查,结果最近两次比赛都死在了A题上... A题一上来把n, ...

  10. Python学习day41-数据库(1)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...