Leecode刷题之旅-C语言/python-389 找不同
/*
* @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 找不同的更多相关文章
- Leecode刷题之旅-C语言/python-1.两数之和
开学后忙的焦头烂额(懒得很),正式开始刷leecode的题目了. 想了想c语言是最最基础的语言,虽然有很多其他语言很简单,有更多的函数可以用,但c语言能煅炼下自己的思考能力.python则是最流行的语 ...
- Leecode刷题之旅-C语言/python-387 字符串中的第一个唯一字符
/* * @lc app=leetcode.cn id=387 lang=c * * [387] 字符串中的第一个唯一字符 * * https://leetcode-cn.com/problems/f ...
- Leecode刷题之旅-C语言/python-28.实现strstr()
/* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...
- Leecode刷题之旅-C语言/python-7.整数反转
/* * @lc app=leetcode.cn id=7 lang=c * * [7] 整数反转 * * https://leetcode-cn.com/problems/reverse-integ ...
- Leecode刷题之旅-C语言/python-434 字符串中的单词数
/* * @lc app=leetcode.cn id=434 lang=c * * [434] 字符串中的单词数 * * https://leetcode-cn.com/problems/numbe ...
- Leecode刷题之旅-C语言/python-326 3的幂
/* * @lc app=leetcode.cn id=326 lang=c * * [326] 3的幂 * * https://leetcode-cn.com/problems/power-of-t ...
- Leecode刷题之旅-C语言/python-263丑数
/* * @lc app=leetcode.cn id=263 lang=c * * [263] 丑数 * * https://leetcode-cn.com/problems/ugly-number ...
- Leecode刷题之旅-C语言/python-383赎金信
/* * @lc app=leetcode.cn id=383 lang=c * * [383] 赎金信 * * https://leetcode-cn.com/problems/ransom-not ...
- Leecode刷题之旅-C语言/python-349两整数之和
/* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...
- Leecode刷题之旅-C语言/python-349两个数组的交集
/* * @lc app=leetcode.cn id=349 lang=c * * [349] 两个数组的交集 * * https://leetcode-cn.com/problems/inters ...
随机推荐
- 计算机应用基础PPT flash作业
- 等待事件P1 P2 P3含义
从以下两个视图中查到的session中,有P1,P2,P3参数select * from v$sessionselect * from v$session_waitselect * from v$se ...
- wind10优化
windows10启动优化 启动时: 1)关闭windows自动更新 2)关闭windows防火墙 3)关闭Windows Defender (1)使用快捷键(WIN+R)调出运行工具,然后再输入组策 ...
- December 09th 2016 Week 50th Friday
In books lies the soul of the whole past time. 书中有所有先贤的全部灵魂. I must know that if I run my business i ...
- Spring Security 静态资源访问
在搞 Spring Security 的时候遇到了一个小坑,就是静态资源加载的问题. 当我们继承了 WebSecurityConfigurerAdapter的时候,会去重写几个方法.去设定我们自己要过 ...
- JavaScript 变量声明提升
JavaScript 变量声明提升 一.变量提升的部分只是变量的声明,赋值语句和可执行的代码逻辑还保持在原地不动 二.在基本的语句(或者说代码块)中(比如:if语句.for语句.while语句.swi ...
- Ubuntu 12.04中MyEclipse 10.6+下载+安装+破解
至于MyEclipse在Ubuntu的安装教程网上很多,那我为什么我还写这篇文章呢?这次重装Ubuntu之后, 在安装MyEclipse 10.6过程中遇到了一个问题,所以把MyEclipse的安装方 ...
- Redux 源码解读 —— 从源码开始学 Redux
已经快一年没有碰过 React 全家桶了,最近换了个项目组要用到 React 技术栈,所以最近又复习了一下:捡起旧知识的同时又有了一些新的收获,在这里作文以记之. 在阅读文章之前,最好已经知道如何使用 ...
- Html5 移动应用软件开发框架 JqueryMobile SenchaTouch 介绍
一.JqueryMobile 介绍 jQuery Mobile 是 jQuery 在手机上和平板设备上的版本. jQuery Mobile 不仅会给主流移动平台带来 jQuery 核心库,而且会发布一 ...
- python中的装饰
在面向对象(OOP)的设计模式中,decorator被称为装饰模式.OOP的装饰模式需要通过继承和组合来实现,而Python除了能支持OOP的decorator外,直接从语法层次支持decorator ...