国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 嘉鱼县| 安龙县| 措美县| 皮山县| 舞钢市| 潜山县| 临邑县| 新野县| 大足县| 万山特区| 白河县| 湘西| 商南县| 阿拉尔市| 林芝县| 通渭县| 华蓥市| 宁蒗| 竹溪县| 铜川市| 彩票| 遂昌县| 怀化市| 海门市| 望城县| 中方县| 南丰县| 隆安县| 元江| 宾阳县| 山东省| 沧州市| 吴旗县| 静安区| 中西区| 南充市| 佛山市| 吉安县| 和平县| 许昌县| 新河县|