Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bd55499

Browse files
Create 619-biggest_single_number.sql
1 parent 9bc4c67 commit bd55499

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

619-biggest_single_number.sql

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
-- 619. Biggest Single Number
2+
3+
-- Table: MyNumbers
4+
5+
-- +-------------+------+
6+
-- | Column Name | Type |
7+
-- +-------------+------+
8+
-- | num | int |
9+
-- +-------------+------+
10+
11+
-- This table may contain duplicates (In other words, there is no primary key for this table in SQL).
12+
-- Each row of this table contains an integer.
13+
14+
15+
-- A single number is a number that appeared only once in the MyNumbers table.
16+
-- Find the largest single number. If there is no single number, report null.
17+
-- The result format is in the following example.
18+
19+
20+
21+
-- Example 1:
22+
23+
-- Input:
24+
-- MyNumbers table:
25+
26+
-- +-----+
27+
-- | num |
28+
-- +-----+
29+
-- | 8 |
30+
-- | 8 |
31+
-- | 3 |
32+
-- | 3 |
33+
-- | 1 |
34+
-- | 4 |
35+
-- | 5 |
36+
-- | 6 |
37+
-- +-----+
38+
39+
-- Output:
40+
-- +-----+
41+
-- | num |
42+
-- +-----+
43+
-- | 6 |
44+
-- +-----+
45+
46+
-- Explanation: The single numbers are 1, 4, 5, and 6.
47+
-- Since 6 is the largest single number, we return it.
48+
-- Example 2:
49+
50+
-- Input:
51+
-- MyNumbers table:
52+
-- +-----+
53+
-- | num |
54+
-- +-----+
55+
-- | 8 |
56+
-- | 8 |
57+
-- | 7 |
58+
-- | 7 |
59+
-- | 3 |
60+
-- | 3 |
61+
-- | 3 |
62+
-- +-----+
63+
64+
-- Output:
65+
-- +------+
66+
-- | num |
67+
-- +------+
68+
-- | null |
69+
-- +------+
70+
71+
-- Explanation: There are no single numbers in the input table so we return null.
72+
73+
74+
SELECT
75+
MAX(unique_nums.num) AS num
76+
FROM
77+
(
78+
SELECT num
79+
FROM MyNumbers
80+
GROUP BY num
81+
HAVING COUNT(num) = 1
82+
) AS unique_nums
83+
;

0 commit comments

Comments
 (0)