当前位置:网站首页>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)
边栏推荐
- idea插件备份表
- IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
- Feature pyramid networks for object detection
- 深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
- 过滤器 Filter
- 报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
- leetcode 1818 绝对值,排序,二分法,最大值
- 整合阿里云短信的问题:无法从静态上下文中引用非静态方法
- [small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation
- Ultimate dolls 2.0 | encapsulation of cloud native delivery
猜你喜欢

LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)

Keil5中如何做到 0 Error(s), 0 Warning(s).
![[nine day training] content III of the problem solution of leetcode question brushing Report](/img/7e/1e76181e56ef7feb083f9662df71c7.jpg)
[nine day training] content III of the problem solution of leetcode question brushing Report

SEM of C language_ Tvariable type

IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does

Implement pow (x, n) function

谷粒学院微信扫码登录过程记录以及bug解决

The combination of applet container technology and IOT

Data exchange JSON

Asgnet paper and code interpretation 2
随机推荐
JUC learning
torch.histc
Split(), split(), slice(), can't you tell?
Overview of EtherCAT principle
Gorilla/mux framework (RK boot): RPC error code design
在 C 中声明函数之前调用函数会发生什么?
shell脚本使用两个横杠接收外部参数
谷粒学院微信扫码登录过程记录以及bug解决
Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page
multiple linear regression
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
Filter
Leetcode 1818 absolute value, sorting, dichotomy, maximum value
Feign远程调用和Getaway网关
Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
Detailed explanation of ES6 deconstruction grammar
在线公网安备案保姆级教程【伸手党福利】
ASGNet论文和代码解读2
ECMAScript 6.0
File upload and download