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

Commit affd056

Browse files
author
Shuo
authored
Merge pull request #316 from openset/develop
Add: Winning Candidate
2 parents b0abda7 + 77f6a90 commit affd056

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

‎problems/winning-candidate/README.md‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
## 574. Winning Candidate
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
27

8+
## 574. Winning Candidate (Medium)
9+
10+
<p>Table: <code>Candidate</code></p>
11+
<pre>
12+
+-----+---------+
13+
| id | Name |
14+
+-----+---------+
15+
| 1 | A |
16+
| 2 | B |
17+
| 3 | C |
18+
| 4 | D |
19+
| 5 | E |
20+
+-----+---------+
21+
</pre>
22+
<p>Table: <code>Vote</code></p>
23+
<pre>
24+
+-----+--------------+
25+
| id | CandidateId |
26+
+-----+--------------+
27+
| 1 | 2 |
28+
| 2 | 4 |
29+
| 3 | 3 |
30+
| 4 | 2 |
31+
| 5 | 5 |
32+
+-----+--------------+
33+
id is the auto-increment primary key,
34+
CandidateId is the id appeared in Candidate table.
35+
</pre>
36+
37+
<p>Write a sql to find the name of the winning candidate, the above example will return the winner <code>B</code>.</p>
38+
39+
<pre>
40+
+------+
41+
| Name |
42+
+------+
43+
| B |
44+
+------+
45+
</pre>
46+
47+
<p><b>Notes:</b><br />
48+
<ol>
49+
<li>You may assume <b>there is no tie</b>, in other words there will be <b>at most one</b> winning candidate.</li>
50+
</ol></p>

‎problems/winning-candidate/winning_candidate.go‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Write your MySQL query statement below
2+
3+
SELECT `name` AS 'Name'
4+
FROM
5+
Candidate
6+
JOIN (
7+
SELECT Candidateid
8+
FROM
9+
Vote
10+
GROUP BY
11+
Candidateid
12+
ORDER BY
13+
COUNT(*) DESC
14+
LIMIT 1
15+
) AS winner
16+
WHERE
17+
Candidate.id = winner.Candidateid;

‎problems/winning-candidate/winning_candidate_test.go‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /