FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_24/Leetcode_242_024.rb at master · algorithm001/algorithm · GitHub
algorithm001
/
algorithm
Public
Notifications
You must be signed in to change notification settings
Fork
148
Star
118
Code
Issues
548
Pull requests
46
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_01
/
id_24
/
Leetcode_242_024.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (39 loc) · 803 Bytes
Breadcrumbs
algorithm
/
Week_01
/
id_24
/
Leetcode_242_024.rb
Copy path
File metadata and controls
40 lines (39 loc) · 803 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
39
40
# 解法一
def
is_anagram
(
s
,
t
)
source_hash
=
{
}
s
.
each_char
{
|
s
|
if
source_hash
[
s
]
source_hash
[
s
]
+=
1
else
source_hash
[
s
]
=
1
end
}
t
.
each_char
{
|
t
|
return
false
unless
source_hash
.
keys
.
include?
t
source_hash
[
t
]
-=
1
source_hash
.
delete_if
{
|
_
,
value
|
value
==
0
}
}
return
true
if
source_hash
.
empty?
return
false
end
#解法二
def
is_anagram
(
s
,
t
)
x
=
Array
.
new
(
26
,
0
)
for
i
in
0
..
s
.
length
-
1
do
value
=
s
[
i
]
.
ord
-
97
x
[
value
]
?
x
[
value
]
+=
1
:
x
[
value
]
=
0
end
for
j
in
0
..
t
.
length
-
1
do
value
=
t
[
j
]
.
ord
-
97
return
false
if
x
[
value
]
==
0
x
[
value
]
-=
1
end
return
true
if
x
.
sum
==
0
return
false
end
# 解法三
def
is_anagram
(
s
,
t
)
s_sort
=
s
.
split
(
""
)
.
sort
t_sort
=
t
.
split
(
""
)
.
sort
s_sort
==
t_sort
end
Back
|
FazBrowse Home
|
New Git URL