问题描述:

给定两个字符串 st,它们只包含小写字母。

字符串 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--找不同的更多相关文章

  1. Java实现 LeetCode 389 找不同

    389. 找不同 给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = " ...

  2. LeetCode 389——找不同

    1. 题目 2. 解答 2.1. 方法一 将 s 和 t 转化为 Python 的列表,然后遍历列表 s 的元素,将它们从列表 t 中删除,最后列表 t 中会余下一个元素,即为所求. class So ...

  3. 【LeetCode】389.找不同

    389.找不同 知识点:哈希表.抵消思想: 题目描述 给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. ...

  4. 力扣(LeetCode)389. 找不同

    给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = "abcd&quo ...

  5. LeetCode 513. 找树左下角的值(Find Bottom Left Tree Value)

    513. 找树左下角的值 513. Find Bottom Left Tree Value 题目描述 给定一个二叉树,在树的最后一行找到最左边的值. LeetCode513. Find Bottom ...

  6. LeetCode.1002-寻找共有字符(Find Common Characters)

    这是悦乐书的第375次更新,第402篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第236题(顺位题号是1002).给定仅由小写字母组成的字符串A,返回列表中所有字符串都 ...

  7. 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 ...

  8. 位运算 leecode.389. 找不同

    //给定两个字符串 s 和 t,它们只包含小写字母. //字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. //请找出在 t 中被添加的字母 char findTheDifferenc ...

  9. LeetCode 389 Find the Difference 解题报告

    题目要求 Given two strings s and t which consist of only lowercase letters. String t is generated by ran ...

  10. leetcode ex3 找出穿过最多点的直线 Max Points on a Line

    题目 https://oj.leetcode.com/problems/max-points-on-a-line/ 答案与分析 http://www.aiweibang.com/yuedu/18326 ...

随机推荐

  1. MongoDB ReplicaSet 集群搭建

    说明 本文创建的集群的名字为test,在同一台机器上创建了三个mongo实例,端口不同即可. 安装mongodb的教程,之前总结过,请参考:CentOS安装MongoDB笔记 创建实例 # 本机默认原 ...

  2. makefile基本操作

    多数内容copy自youtube的一个视频:https://www.youtube.com/watch?v=E1_uuFWibuM 执行环境:原作者是在Linux下做的视频,而我使用的是win10,w ...

  3. 怎样建立你自己的MASM导入库

    by Iczelion (翻译:花心萝卜yqzq@163.net) 9.5.2000 这篇短文是讲述关于建立MASM导入库(import libraries)技巧,我假设你已经知道什么是导入库.在下面 ...

  4. SQLServer 取 字段名称 类型 字段描述 等

    https://www.cnblogs.com/w2011/archive/2013/01/04/2844143.html SELECT 字段名= convert(varchar(100), a.na ...

  5. 深度学习课程笔记(三)Backpropagation 反向传播算法

    深度学习课程笔记(三)Backpropagation 反向传播算法 2017.10.06  材料来自:http://speech.ee.ntu.edu.tw/~tlkagk/courses_MLDS1 ...

  6. 论文笔记之:Optical Flow Estimation using a Spatial Pyramid Network

    Optical Flow Estimation using a Spatial Pyramid Network   spynet  本文将经典的 spatial-pyramid formulation ...

  7. 今天就整一个bug了

    BeanPostProcessor加载次序及其对Bean造成的影响分析 SSM整合出现not found for dependency: expected at least 1 bean which ...

  8. .NET 介绍

    In order to continue our effort of being modular and well factored we don’t just provide the entire ...

  9. sql注入解析

    sql注入解析 sql注入解析(一)基本语法 sql注入解析(二)执行注入 sql注入解析(三)数据库类型 sql注入解析(四)避开过滤

  10. VirtualBox--虚拟机网络设置1--(四种方式)

    转载自:https://www.douban.com/group/topic/15558388/ VirtualBox的提供了四种网络接入模式,它们分别是: 1.NAT 网络地址转换模式(NAT,Ne ...