LeetCode--389--找不同
问题描述:
给定两个字符串 s 和 t,它们只包含小写字母。
字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。
示例:
输入:
s = "abcd"
t = "abcde" 输出:
e 解释:
'e' 是那个被添加的字母。
方法1:
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
for i in t:
if i not in s:
return i
elif s.count(i) != t.count(i):
return i
amazing:
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
num_s = 0
num_t = 0
for i in s:
num_s += ord(i)
for i in t:
num_t += ord(i)
return chr(num_t -num_s)
2018-09-29 06:58:05
LeetCode--389--找不同的更多相关文章
- Java实现 LeetCode 389 找不同
389. 找不同 给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = " ...
- LeetCode 389——找不同
1. 题目 2. 解答 2.1. 方法一 将 s 和 t 转化为 Python 的列表,然后遍历列表 s 的元素,将它们从列表 t 中删除,最后列表 t 中会余下一个元素,即为所求. class So ...
- 【LeetCode】389.找不同
389.找不同 知识点:哈希表.抵消思想: 题目描述 给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. ...
- 力扣(LeetCode)389. 找不同
给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = "abcd&quo ...
- LeetCode 513. 找树左下角的值(Find Bottom Left Tree Value)
513. 找树左下角的值 513. Find Bottom Left Tree Value 题目描述 给定一个二叉树,在树的最后一行找到最左边的值. LeetCode513. Find Bottom ...
- LeetCode.1002-寻找共有字符(Find Common Characters)
这是悦乐书的第375次更新,第402篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第236题(顺位题号是1002).给定仅由小写字母组成的字符串A,返回列表中所有字符串都 ...
- 9. leetcode 389. Find the Difference
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- 位运算 leecode.389. 找不同
//给定两个字符串 s 和 t,它们只包含小写字母. //字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. //请找出在 t 中被添加的字母 char findTheDifferenc ...
- LeetCode 389 Find the Difference 解题报告
题目要求 Given two strings s and t which consist of only lowercase letters. String t is generated by ran ...
- leetcode ex3 找出穿过最多点的直线 Max Points on a Line
题目 https://oj.leetcode.com/problems/max-points-on-a-line/ 答案与分析 http://www.aiweibang.com/yuedu/18326 ...
随机推荐
- PT,PX,DPI
[iOS]查找数组NSArray中是否包含指定的元素 http://blog.csdn.net/zyq527758142/article/details/51278172 Dpi(每平方英寸像素数目) ...
- phpMyAdmin - Error
centos7.5 原因:权限问题 解决方法:授权 [root@web01 code]# groupadd -g666 www [root@web01 code]# useradd -u666 -g6 ...
- 求最大流dinic算法模板
//最短增广路,Dinic算法 struct Edge { int from,to,cap,flow; };//弧度 void AddEdge(int from,int to,int cap) //增 ...
- HDU 5929 Basic Data Structure(模拟 + 乱搞)题解
题意:给定一种二进制操作nand,为 0 nand 0 = 10 nand 1 = 1 1 nand 0 = 1 1 nand 1 = 0 现在要你模拟一个队列,实现PUSH x 往队头塞入x,POP ...
- Docker部署微服务
部署时需要注!意!: 打开防火墙对应的应用端口!!用于外部访问!!内部互访问则不需要. 和对应数据库,缓存,消息中间件服务等的端口(当然这些服务必须先开启,它们也可使用docker部署开启) ,用于容 ...
- hihoCoder week3 KMP算法
题目链接 https://hihocoder.com/contest/hiho3/problems kmp算法 #include <bits/stdc++.h> using namespa ...
- 字符串模版,替代原来Es5的+号拼装字符串
字符串模版 这节我们主要学习ES6对字符串新增的操作,最重要的就是字符串模版,字符串模版的出现让我们再也不用拼接变量了,而且支持在模板里有简单计算操作.小伙伴们是不是已经摩拳擦掌等不急了那?那我们就开 ...
- VirtuablBox 出错: VERR_SUPLIB_OWNER_NOT_ROOT 解决方法
刚刚把 VirtualBox 升级, 从 3.2 到 4.0.4 后,虚拟机上的系统无法运行, 提示: VERR_SUPLIB_OWNER_NOT_ROOT 查了一下,发现是因为 /opt 的 own ...
- vscode "没有活动的源代码控制提供程序" 解决办法
确保安装git F1,输入Show built-in Extensions, 左侧列表中找Git,然后启用即可
- 批量Excel数据导入Oracle数据库
由于一直基于Oracle数据库上做开发,因此常常会需要把大量的Excel数据导入到Oracle数据库中,其实如果从事SqlServer数据库的开发,那么思路也是一样的,本文主要介绍如何导入Excel数 ...