Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56b9a57

Browse files
committed
Added code for problems solved in Weekly contest 103
1 parent219c0de commit56b9a57

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
classTopVotedCandidate {
2+
int[]times;
3+
int[]persons;
4+
int[]winner;
5+
6+
publicTopVotedCandidate(int[]persons,int[]times) {
7+
this.times =times;
8+
this.persons =persons;
9+
int[]counter =newint[persons.length+1];
10+
winner =newint[times.length];
11+
intmax =Integer.MIN_VALUE;
12+
intmaxPerson = -1;
13+
inti =0;
14+
15+
while (i <times.length) {
16+
counter[persons[i]]++;
17+
if (max <counter[persons[i]]) {
18+
max =counter[persons[i]];
19+
maxPerson =persons[i];
20+
}
21+
elseif (max ==counter[persons[i]]) {
22+
maxPerson =persons[i];
23+
}
24+
25+
winner[i] =maxPerson;
26+
27+
i++;
28+
}
29+
}
30+
31+
publicintq(intt) {
32+
inti =0;
33+
while (i <times.length &&times[i] <=t) {
34+
i++;
35+
}
36+
37+
returnwinner[i-1];
38+
}
39+
}
40+
41+
42+
/**
43+
* Your TopVotedCandidate object will be instantiated and called as such:
44+
* TopVotedCandidate obj = new TopVotedCandidate(persons, times);
45+
* int param_1 = obj.q(t);
46+
*/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
classSolution {
2+
3+
publicstaticintsmallestRangeI(int[]A,intK) {
4+
Arrays.sort(A);
5+
returnMath.max((A[A.length-1] -K) - (A[0] +K),0);
6+
}
7+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp