FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/find-the-difference.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
find-the-difference.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (31 loc) · 950 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
find-the-difference.py
Copy path
File metadata and controls
40 lines (31 loc) · 950 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Time: O(n)
# Space: O(1)
import
operator
import
collections
from
functools
import
reduce
class
Solution
(
object
):
def
findTheDifference
(
self
,
s
,
t
):
"""
:type s: str
:type t: str
:rtype: str
"""
return
chr
(
reduce
(
operator
.
xor
,
map
(
ord
,
s
),
0
)
^
reduce
(
operator
.
xor
,
map
(
ord
,
t
),
0
))
def
findTheDifference2
(
self
,
s
,
t
):
"""
:type s: str
:type t: str
:rtype: str
"""
t
=
list
(
t
)
s
=
list
(
s
)
for
i
in
s
:
t
.
remove
(
i
)
return
t
[
0
]
def
findTheDifference3
(
self
,
s
,
t
):
return
chr
(
reduce
(
operator
.
xor
,
map
(
ord
,
s
+
t
)))
def
findTheDifference4
(
self
,
s
,
t
):
return
list
((
collections
.
Counter
(
t
)
-
collections
.
Counter
(
s
)))[
0
]
def
findTheDifference5
(
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
]
Back
|
FazBrowse Home
|
New Git URL