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 ...
随机推荐
- [翻译] JTBorderDotAnimation
JTBorderDotAnimation https://github.com/jonathantribouharet/JTBorderDotAnimation JTBorderDotAnimatio ...
- 测试你的 In-app Billing 程序
测试你的 In-app Billing 程序 为了保证 In-app Billing 可以在你程序中正常使用,你应该在把应用程序发布到Google Play之前进行测试.早期的测试有助于确保用户对于你 ...
- 乘风破浪:LeetCode真题_019_Remove Nth Node From End of List
乘风破浪:LeetCode真题_019_Remove Nth Node From End of List 一.前言 这次总算到了链表的操作了,之后肯定会有排序算法,二叉树,排序树,图等等的操作,现在我 ...
- php非空验证
我想说这种方法是不是很常用的非空验证,现在的普遍使用的是javascript来验证非空,但是作为学习php的一些知识点,还是可以看看的. 先来看看commit.php中的方法 <?php $db ...
- jquery.form.js(ajax表单提交)
Form插件地址: 官方网站:http://malsup.com/jQuery/form/ 翻译地址:http://www.aqee.net/docs/jquery.form.plugin/jquer ...
- oracle 查看主外键约束
select a.constraint_name, a.table_name, b.constraint_name from user_constraints a, user_constraints ...
- A blog about Core Animation and other iOS graphics framework
A blog about Core Animation and other iOS graphics frameworks. https://www.calayer.com/
- TCP传输层协议的流程
http://blog.chinaunix.net/uid-24399976-id-77905.html 通过对互联网的认识,我们发现TCP传输层协议是网络进行工作的核心也是基础.它的重要性我们在此也 ...
- 2、Android-UI(关于Nine-Patch图片)
实例: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...
- leetcode 121. Best Time to Buy and Sell Stock 、122.Best Time to Buy and Sell Stock II 、309. Best Time to Buy and Sell Stock with Cooldown
121. Best Time to Buy and Sell Stock 题目的要求是只买卖一次,买的价格越低,卖的价格越高,肯定收益就越大 遍历整个数组,维护一个当前位置之前最低的买入价格,然后每次 ...