给定两个字符串 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. 阿里云服务器安装Python3.8

    1.操作系统: CentOS 7.4 64位 2.下载python安装包 wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.x ...

  2. Censored! POJ - 1625 AC自动机+大数DP

    题意: 给出一n种字符的字典,有p个禁用的单词, 问能组成多少个不同的长度为m的合法字符串.(m<=50) 题解: 是不是个我们之前做的题目非常非常像,题意都一样. 直接将上次写的AC自动机+矩 ...

  3. sql 分组统计查询并横纵坐标转换

    关于sql 分组统计查询,我们在做报表的时候经常需要用到;今天就在这里整理下; 先附上一段sql代码: if object_id(N'#mytb',N'U') is not null drop tab ...

  4. (转)nginx配置location总结及rewrite规则写法

    注: rewrite 只能对域名后边的除去传递的参数外的字符串起作用,并且要写全域名后面的部分,如: http://i.com:9090/php/midou/admin.php/index/login ...

  5. 在js中使用Razor

    @foreach (var tem in Model) { <text> time.push("@tem.CreateTime.ToString("G")&q ...

  6. QTableView的indexAt使用方法

    要实现的功能是QTableview中Item项上右键弹出菜单这就必然要判断点击右键时鼠标指针是否在QTableView的Item上 如果是QTableWidget可以用itemAt来判断QTableV ...

  7. Codeforces 839D Winter is here

    链接:CF839D 题目大意 给定一个数组大小为\(n(1\leq n\leq 200000)\)的数组\(a\),满足\(1\leq a_i \leq 1000000\). 选择其中任意\(len\ ...

  8. synchronized ReentrantLock 比较分析

    在编写多线程代码的时候,对于不允许并发的代码,很多需要加锁进行处理.在进行加锁处理时候,synchronized作为java的内置锁,同时也是java关键字,最为被人熟知,即使是最初级的java程序员 ...

  9. zabbix被监控端代理设置

    zabbix被监控端代理设置 安装zabbix-agent客户端 rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-re ...

  10. Python中实现对list做减法操作介绍

    Python中实现对list做减法操作介绍 这篇文章主要介绍了Python中实现对list做减法操作介绍,需要的朋友可以参考下 问题描述:假设我有这样两个list, 一个是list1,list1 = ...