LeetCode389Find the Difference找不同
给定两个字符串 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找不同的更多相关文章
- 389 Find the Difference 找不同
给定两个字符串 s 和 t,它们只包含小写字母.字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母.请找出在 t 中被添加的字母.示例:输入:s = "abcd"t = ...
- 389. Find the Difference 找出两个字符串中多余的一个字符
[抄题]: Given two strings s and t which consist of only lowercase letters. String t is generated by ra ...
- C++ 迭代器容器学习
set的一个用法 . difference找差集 union合并set intersection找到交集 #include<iostream> #include<string> ...
- LeetCode-day05
45. Single Number 在个数都为2的数组中找到个数为1的数 46. Missing Number 在数组中找到从0到n缺失的数字 47. Find the Difference 找两个字 ...
- day004-python运算符与基本数据类型
一.运算符1.算术运算符:主要用于两个对象算数计算(加减乘除等运算)运算符: +:两个对象相加 -:得到负数或是一个数减去另一个数 *:两个数相乘或是返回一个被重复若干次的字符串 /:x除以y %:返 ...
- Python【集合】、【函数】、【三目运算】、【lambda】、【文件操作】
set集合: •集合的创建; set_1 = set() #方法一 set_1 = {''} #方法二 •set是无序,不重复的集合; set_1 = {'k1','k2','k3'} set_1.a ...
- [Swift]LeetCode389. 找不同 | Find the Difference
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- 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 ...
- 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 ...
随机推荐
- Jumpserver-1.5.2 安装步骤
Jumpsever 是飞致云旗下的一块开源的堡垒机.在如今都在上云的趋势下,一款堡垒机非常重要. 官网:http://jumpserver.org/ GitHub:https://github.com ...
- wpf Rectangle
<Rectagle Width="100" Height="100" Stroke="Black" Fill="Blue&q ...
- [转]Entity Framework 的实体关系
通过 Entiy Framework实践系列 文章,理了理 Entity Framework 的实体关系. 为什么要写文章来理清这些关系?“血”的教训啊,刚开始使用 Entity Framework ...
- P3480 [POI2009]KAM-Pebbles
P3480 [POI2009]KAM-Pebbles比如第一个样例 原:0 2 2差: 2 0 0如果把中间的2拿掉一个,就会变成原:0 1 2差: 1 1 0就可以把差看成阶梯nim细节:最终要移到 ...
- 使用node.js实现反向代理
一. 反向代理的应用场景 1. 静态资源与动态资源分离 e.g. 图片服务器 2. AJAX跨域访问 3. 搭建统一服务网关接口 二. 使用node.js实现反向代理 1. 安装http-proxy模 ...
- odoo js
1.相关库/框架 主要:jQuery(使用1.8.3,如果使用新版本,其他jQuery插件也要升级或修改).Underscore.QWeb 其他:都在addons\web\static\lib路径下. ...
- git归纳总结
1,git 是分布式版本控制:单个电脑就是一个完整的版本库,只需向中央服务器(远程服务器)提交修改的部分.在没有网络情况下也能正常想本机服务器提交代码管理版本,有网时再推送到远程服务器. svn是 ...
- 洛谷P4550 【收集邮票】
题目链接: 神仙题QAQ 题目分析: 概率期望题是不可能会的,一辈子都不可能会的QAQ 这个题也太仙了 首先明确一下题意里面我感觉没太说清楚的地方,这里是抽到第\(i\)次要\(i\)元钱,不是抽到第 ...
- 在scrapy中过滤重复的数据
当为了确保爬到的数据中没有重复的数据的时候,可以实现一个去重的item pipeline 增加构造器方法,在其中初始化用于对与书名的去重的集合 在process_item方法中,先取出item中要判断 ...
- 如何做系列(5)-james mail安装总结
安装james还是比较复杂的,我们在EC2上花费了差不多一天,发现不能发送邮件到外网,后续又陆续花了几天的时间,才成功搭建james邮件服务器. 现在愿意把我们的经历分享出来,让大家参考一下. 由于项 ...