/*
* @lc app=leetcode.cn id=389 lang=c
*
* [389] 找不同
*
* https://leetcode-cn.com/problems/find-the-difference/description/
*
* algorithms
* Easy (54.68%)
* Total Accepted: 7.1K
* Total Submissions: 12.9K
* Testcase Example: '"abcd"\n"abcde"'
*
* 给定两个字符串 s 和 t,它们只包含小写字母。
*
* 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
*
* 请找出在 t 中被添加的字母。
*
*
*
* 示例:
*
* 输入:
* s = "abcd"
* t = "abcde"
* 输出:
* e
*
* 解释:
* 'e' 是那个被添加的字母。
*
*
*/
char findTheDifference(char* s, char* t) {
int len=strlen(s); int result=(int)t[];
for(int i=;i<len;i++){
result^=s[i];
result^=t[i+];
}
return (char)result;
}

相同的数异或为0,而俩数组只有一个字母不同,所以只要全都异或一遍就只剩下那个不同的字母的ascuii码,ascuii码是int类型,只要强制类型转换为char就行了。

#
# @lc app=leetcode.cn id=389 lang=python3
#
# [389] 找不同
#
# https://leetcode-cn.com/problems/find-the-difference/description/
#
# algorithms
# Easy (54.68%)
# Total Accepted: 7.1K
# Total Submissions: 12.9K
# Testcase Example: '"abcd"\n"abcde"'
#
# 给定两个字符串 s 和 t,它们只包含小写字母。
#
# 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
#
# 请找出在 t 中被添加的字母。
#
#
#
# 示例:
#
# 输入:
# s = "abcd"
# t = "abcde"
#
# 输出:
# e
#
# 解释:
# 'e' 是那个被添加的字母。
#
#
#
class Solution:
def findTheDifference(self, s: str, t: str) -> str:
ch=0
for c in s+t:
ch^=ord(c)
return chr(ch)

Leecode刷题之旅-C语言/python-389 找不同的更多相关文章

  1. Leecode刷题之旅-C语言/python-1.两数之和

    开学后忙的焦头烂额(懒得很),正式开始刷leecode的题目了. 想了想c语言是最最基础的语言,虽然有很多其他语言很简单,有更多的函数可以用,但c语言能煅炼下自己的思考能力.python则是最流行的语 ...

  2. Leecode刷题之旅-C语言/python-387 字符串中的第一个唯一字符

    /* * @lc app=leetcode.cn id=387 lang=c * * [387] 字符串中的第一个唯一字符 * * https://leetcode-cn.com/problems/f ...

  3. Leecode刷题之旅-C语言/python-28.实现strstr()

    /* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...

  4. Leecode刷题之旅-C语言/python-7.整数反转

    /* * @lc app=leetcode.cn id=7 lang=c * * [7] 整数反转 * * https://leetcode-cn.com/problems/reverse-integ ...

  5. Leecode刷题之旅-C语言/python-434 字符串中的单词数

    /* * @lc app=leetcode.cn id=434 lang=c * * [434] 字符串中的单词数 * * https://leetcode-cn.com/problems/numbe ...

  6. Leecode刷题之旅-C语言/python-326 3的幂

    /* * @lc app=leetcode.cn id=326 lang=c * * [326] 3的幂 * * https://leetcode-cn.com/problems/power-of-t ...

  7. Leecode刷题之旅-C语言/python-263丑数

    /* * @lc app=leetcode.cn id=263 lang=c * * [263] 丑数 * * https://leetcode-cn.com/problems/ugly-number ...

  8. Leecode刷题之旅-C语言/python-383赎金信

    /* * @lc app=leetcode.cn id=383 lang=c * * [383] 赎金信 * * https://leetcode-cn.com/problems/ransom-not ...

  9. Leecode刷题之旅-C语言/python-349两整数之和

    /* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...

  10. Leecode刷题之旅-C语言/python-349两个数组的交集

    /* * @lc app=leetcode.cn id=349 lang=c * * [349] 两个数组的交集 * * https://leetcode-cn.com/problems/inters ...

随机推荐

  1. java获取中文拼音首字母

    import net.sourceforge.pinyin4j.PinyinHelper; public class PinyinHelperUtil { /** * 得到中文首字母(中国 -> ...

  2. Spring学习---Spring中利用组件实现从FTP服务器上传/下载文件

    FtpUtil.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcepti ...

  3. PTA | Maximum Subsequence Sum

    Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to ...

  4. select poll epoll Linux高并发网络编程模型

    0 发展历程 同步阻塞迭代模型-->多进程并发模型-->多线程并发模型-->select-->poll-->epoll-->... 1 同步阻塞迭代模型 bind( ...

  5. python虚拟环境virtualenv高级篇

    我曾经写过一篇virtualenv的博客:http://www.cnblogs.com/anpengapple/p/5907416.html 总体来讲还是适用的,不过稍微傻了一点.这一篇的内容有两个: ...

  6. SOJ 1089 FatMouse的奶酪 暴力

    BackGround FatMouse拥有许多奶酪,所有的奶酪都有一个彼此不同的重量.FatMouse为了控制它自己的体重,在每天早上它都会计算今天应该吃多少奶酪才能无痛苦地减肥. The Probl ...

  7. linux下搭建禅道项目管理系统

    1.禅道下载:                 #官网:http://www.zentao.net/article-browse-1067.html [root@localhost ~]# wget ...

  8. HDU 1829 A Bug's Life (种类并查集)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Oth ...

  9. Linux mysql 5.5.10 二进制安装过程记录和 修改 密码 登录

    1.useradd clouder2.解压缩mysql.tar.bz2到/home/clouder2.mv /etc/my.cnf /etc/my.cnf.bak3./home/clouder/mys ...

  10. SQL SERVER或oracl如何判断删除列

    ORACLE: BEGIN  EXECUTE IMMEDIATE 'DROP TABLE CUX_PO_VENDORS';EXCEPTION  WHEN OTHERS THEN    NULL;END ...