当前位置:网站首页>389. 找不同
389. 找不同
2022-07-01 03:23:00 【Sun_Sky_Sea】
389. 找不同
原始题目链接:https://leetcode.cn/problems/find-the-difference/
给定两个字符串 s 和 t ,它们只包含小写字母。
字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。
示例 1:
输入:s = “abcd”, t = “abcde”
输出:“e”
解释:‘e’ 是那个被添加的字母。
示例 2:
输入:s = “”, t = “y”
输出:“y”
解题思路:
直接计算ASCII的值即可。
代码实现:
class Solution:
def findTheDifference(self, s: str, t: str) -> str:
ans_s = 0
ans_t = 0
for i in s:
ans_s += ord(i)
for j in t:
ans_t += ord(j)
return chr(ans_t - ans_s)
边栏推荐
- Implement pow (x, n) function
- LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
- Use of comment keyword in database
- Depth first traversal of C implementation Diagram -- non recursive code
- [deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
- Edlines: a real time line segment detector with a false detection control
- Golang multi graph generation gif
- Test function in pychram
- 整合阿里云短信的问题:无法从静态上下文中引用非静态方法
- Detailed explanation of ES6 deconstruction grammar
猜你喜欢

Implement pow (x, n) function

用小程序的技术优势发展产业互联网

BluePrism注册下载并安装-RPA第一章

Binary tree god level traversal: Morris traversal

Explain spark operation mode in detail (local+standalone+yarn)

Gorilla/mux framework (RK boot): RPC error code design

Learning notes for introduction to C language multithreaded programming

Error: plug ins declaring extensions or extension points must set the singleton directive to true

Appium自动化测试基础 — APPium基本原理

访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
随机推荐
Pyramid Scene Parsing Network【PSPNet】论文阅读
torch. histc
JS日常开发小技巧(持续更新)
Test function in pychram
Leetcode: offer 59 - I. maximum value of sliding window
岭回归和lasso回归
Pytorch training deep learning network settings CUDA specified GPU visible
Keil5中如何做到 0 Error(s), 0 Warning(s).
串口接收数据方案设计
Pathmeasure implements loading animation
监听器 Listener
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
Download and installation configuration of cygwin
Listener listener
Ctfshow blasting WP
详解Spark运行模式(local+standalone+yarn)
Blueprism registration, download and install -rpa Chapter 1
leetcode 1482 猜猜看啊,这道题目怎么二分?
网页不能右键 F12 查看源代码解决方案
深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)