FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_02/id_34/LeeCode_692_034.cs at master · feixiangcode/algorithm · GitHub
feixiangcode
/
algorithm
Public
forked from
algorithm001/algorithm
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
algorithm
/
Week_02
/
id_34
/
LeeCode_692_034.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (49 loc) · 1.55 KB
Breadcrumbs
algorithm
/
Week_02
/
id_34
/
LeeCode_692_034.cs
Copy path
File metadata and controls
52 lines (49 loc) · 1.55 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
public
class
Solution
{
public
IList
<
string
>
TopKFrequent
(
string
[
]
words
,
int
k
)
{
int
[
]
wordsTimes
=
new
int
[
words
.
Length
]
;
for
(
int
i
=
words
.
Length
-
1
;
i
>=
0
;
i
--
)
{
for
(
int
j
=
0
;
j
<
i
;
j
++
)
{
if
(
words
[
j
]
==
words
[
i
]
)
{
wordsTimes
[
j
]
++
;
wordsTimes
[
i
]
--
;
break
;
}
}
wordsTimes
[
i
]
++
;
}
List
<
int
>
indexer
=
new
List
<
int
>
(
)
;
while
(
k
>
0
)
{
int
index
=
-
1
;
int
maxValue
=
0
;
for
(
int
i
=
0
;
i
<
wordsTimes
.
Length
;
i
++
)
{
if
(
wordsTimes
[
i
]
>
maxValue
)
{
maxValue
=
wordsTimes
[
i
]
;
index
=
i
;
//wordsTimes[i] = 0;
}
else
if
(
index
>=
0
&&
wordsTimes
[
i
]
==
maxValue
&&
string
.
Compare
(
words
[
index
]
,
words
[
i
]
)
>
0
)
{
maxValue
=
wordsTimes
[
i
]
;
index
=
i
;
}
}
if
(
index
>=
0
)
{
wordsTimes
[
index
]
=
0
;
indexer
.
Add
(
index
)
;
}
k
--
;
}
IList
<
string
>
result
=
new
List
<
string
>
(
)
;
foreach
(
var
item
in
indexer
)
{
result
.
Add
(
words
[
item
]
)
;
}
return
result
;
}
}
Back
|
FazBrowse Home
|
New Git URL