/*
* @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. iOS设计模式 - 适配器

    iOS设计模式 - 适配器 效果 说明 1. 为了让客户端尽可能的通用,我们使用适配器模式来隔离客户端与外部参数的联系,只让客户端与适配器通信. 2. 本教程实现了适配器模式的类适配器与对象适配器两种 ...

  2. mysql在linux下的安装mysql-5.6.33

    一.下载源码包 wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 二.解压源 ...

  3. 【MyBatis】MyBatis实现CRUD操作

    1.实现基本CRUD功能 使用MyBatis对数据完整的操作,也就是CRUD功能的实现.根据之前的内容,要想实现CRUD,只需要进行映射文件的配置. 范例:修改EmpMapper.xml文件,实现CR ...

  4. 乘风破浪:LeetCode真题_013_Roman to Integer

    乘风破浪:LeetCode真题_013_Roman to Integer 一.前言 上一节我们讨论了如何把阿拉伯数字转换成罗马数字,现在我们需要思考一下如何把罗马数字转换成阿拉伯数字,其实我们仔细观擦 ...

  5. pyenv - python版本管理

    1. 安装pyenv brew install pyenv 2. 安装python其它版本(如:python 3.6.7) pyenv install --list #查看可以安装的python版本 ...

  6. Python中readline()函数 去除换行符

    从Python中readline()函数读取的一行内容中含有换行符\n,很多时候我们需要处理不含有换行符的字符串,此时就要去掉换行符\n. 方法是使用strip()函数. 例子如下: f = open ...

  7. 【SQL.基础构建-第四节(4/4)】

    --      Tips:数据更新 --一.插入数据 --1.INSERT 语句的基本语法 --语法:--INSERT INTO <表名>(列1, 列2, ...) VALUES (值1, ...

  8. Webpack知识汇总

    介绍 webpack把任何一个文件都看成是一个模块,模块间可以相互依赖(require or import),webpack的功能就是把相互依赖的文件打包在一起.webpack本身只能处理原生的Jav ...

  9. Bean Definition从加载、解析、处理、注册到BeanFactory的过程。

    为了弄清楚Bean是怎么来的,花费了大把功夫,现在要把Bean Definition的加载.解析.处理.注册到bean工厂的过程记下来.这只是bean definition 的加载.解析.处理.注册过 ...

  10. Linux学习总结(十七)-shell 基础知识

    一 先介绍几种常用字符: 1 * 匹配任意个任意字符2 ?匹配一个任意字符3 # 注释符号,符号后的语句不被执行4 \脱意字符,后面跟带含义字符时,照原字符输出5 []匹配包含在[]之中的任意一个字符 ...