国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Find the Difference

2019-11-08 20:17:04
字體:
供稿:網(wǎng)友
Given two strings s and t which consist of only lowercase letters.

String t is generated by random shuffling string s and then add one more letter at a random position.

Find the letter that was added in t.

Example:

Input:s = "abcd"t = "abcde"Output:eExplanation:'e' is the letter that was added.
1-liners and 2-liner in Python
Using XOR:class Solution(object):    def findTheDifference(self, s, t):        return chr(reduce(Operator.xor, map(ord, s + t)))Using collections.Counter():class Solution(object):    def findTheDifference(self, s, t):        return list((collections.Counter(t) - collections.Counter(s)))[0]A 2-liner here using sorted():class Solution(object):    def findTheDifference(self, s, t):        s, t = sorted(s), sorted(t)        return t[-1] if s == t[:-1] else [x[1] for x in zip(s, t) if x[0] != x[1]][0]
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 高要市| 安多县| 汤阴县| 沈阳市| 澳门| 江口县| 大足县| 汉沽区| 巴中市| 卢龙县| 大厂| 大港区| 岑巩县| 龙陵县| 丹阳市| 娄烦县| 文化| 乌拉特前旗| 汉沽区| 翁牛特旗| 漠河县| 广西| 通城县| 巴彦淖尔市| 巫溪县| 防城港市| 贡山| 雷波县| 南和县| 南漳县| 应城市| 禄丰县| 象山县| 虹口区| 连平县| 铜陵市| 正阳县| 罗山县| 公安县| 日土县| 门头沟区|