File tree Expand file tree Collapse file tree 4 files changed +168
-1
lines changed
customers-who-never-order Expand file tree Collapse file tree 4 files changed +168
-1
lines changed Original file line number Diff line number Diff line change 22
33This is the solution collection of my LeetCode problems, most of them are programmed in JavaScript.
44
5- Progress: 14 /
5+ Progress: 18 /
66
77| ID | Title | Solution | Difficulty |
88| ---| ----- | -------- | ---------- |
99| 1| [ Two Sum] ( https://leetcode.com/problems/two-sum/ ) | [ JavaScript] ( ./src/two-sum/res.js ) | Easy|
1010| 2| [ Add Two Numbers] ( https://leetcode.com/problems/add-two-numbers/ ) | [ JavaScript] ( ./src/add-two-numbers/res.js ) | Medium|
11+ | 7| [ Reverse Integer] ( https://leetcode.com/problems/reverse-integer/ ) | [ JavaScript] ( ./src/reverse-integer/res.js ) | Easy|
12+ | 13| [ Roman to Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | [ JavaScript] ( ./src/roman-to-integer/res.js ) | Easy|
1113| 66| [ Plus One] ( https://leetcode.com/problems/plus-one/ ) | [ JavaScript] ( ./src/plus-one/res.js ) | Easy|
1214| 69| [ Sqrt(x)] ( https://leetcode.com/problems/sqrtx/ ) | [ JavaScript] ( ./src/sqrtx/res.js ) | Easy|
1315| 175| [ Combine Two Tables] ( https://leetcode.com/problems/combine-two-tables/ ) | [ SQL] ( ./src/combine-two-tables/res.txt ) | Easy|
1416| 176| [ Second Highest Salary] ( https://leetcode.com/problems/second-highest-salary/ ) | [ SQL] ( ./src/second-highest-salary/res.txt ) | Easy|
1517| 177| [ Nth Highest Salary] ( https://leetcode.com/problems/nth-highest-salary/ ) | [ SQL] ( ./src/nth-highest-salary/res.txt ) | Medium|
1618| 181| [ Employees Earning More Than Their Managers] ( https://leetcode.com/problems/employees-earning-more-than-their-managers/ ) | [ SQL] ( ./src/employees-earning-more-than-their-managers/res.txt ) | Easy|
1719| 182| [ Duplicate Emails] ( https://leetcode.com/problems/duplicate-emails/ ) | [ SQL] ( ./src/duplicate-emails/res.txt ) | Easy|
20+ | 183| [ Customers Who Never Order] ( https://leetcode.com/problems/customers-who-never-order/ ) | [ SQL] ( ./src/customers-who-never-order/res.txt ) | Easy|
1821| 184| [ Department Highest Salary] ( https://leetcode.com/problems/department-highest-salary/ ) | [ SQL] ( ./src/department-highest-salary/res.txt ) | Medium|
1922| 196| [ Delete Duplicate Emails] ( https://leetcode.com/problems/delete-duplicate-emails/ ) | [ SQL] ( ./src/delete-duplicate-emails/res.txt ) | Easy|
2023| 197| [ Rising Temperature] ( https://leetcode.com/problems/rising-temperature/ ) | [ SQL] ( ./src/rising-temperature/res.txt ) | Easy|
Original file line number Diff line number Diff line change 1+ -- Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.
2+
3+ -- Table: Customers.
4+
5+ -- +----+-------+
6+ -- | Id | Name |
7+ -- +----+-------+
8+ -- | 1 | Joe |
9+ -- | 2 | Henry |
10+ -- | 3 | Sam |
11+ -- | 4 | Max |
12+ -- +----+-------+
13+ -- Table: Orders.
14+
15+ -- +----+------------+
16+ -- | Id | CustomerId |
17+ -- +----+------------+
18+ -- | 1 | 3 |
19+ -- | 2 | 1 |
20+ -- +----+------------+
21+ -- Using the above tables as example, return the following:
22+
23+ -- +-----------+
24+ -- | Customers |
25+ -- +-----------+
26+ -- | Henry |
27+ -- | Max |
28+ -- +-----------+
29+
30+ # Write your MySQL query statement below
31+ SELECT Name AS 'Customers' FROM Customers WHERE Id NOT IN (SELECT DISTINCT(CustomerId) FROM Orders);
Original file line number Diff line number Diff line change 1+ /**
2+ * Reverse digits of an integer.
3+ *
4+ * Example1: x = 123, return 321
5+ * Example2: x = -123, return -321
6+ *
7+ * Note:
8+ * The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
9+ *
10+ * res.js
11+ * @authors Joe Jiang (hijiangtao@gmail.com)
12+ * @date 2017-02-21 21:25:59
13+ * @version $Id$
14+ */
15+
16+ /**
17+ * @param {number } x
18+ * @return {number }
19+ */
20+ var reverse = function ( x ) {
21+ let res = 0 ,
22+ abs = Math . abs ( x ) ,
23+ negative = abs === x ? false :true ;
24+
25+ while ( abs > 0 ) {
26+ let currentVal = abs % 10 ;
27+ res = res * 10 + currentVal ;
28+ abs = Number . parseInt ( abs / 10 ) ;
29+ }
30+
31+ if ( res > Math . pow ( 2 , 31 ) ) {
32+ return 0 ;
33+ } else if ( negative ) {
34+ return - res ;
35+ }
36+
37+ return res ;
38+ } ;
39+
40+ // Another solution wrote in Java
41+ //
42+ // public int reverse(int x)
43+ // {
44+ // int result = 0;
45+
46+ // while (x != 0)
47+ // {
48+ // int tail = x % 10;
49+ // int newResult = result * 10 + tail;
50+ // if ((newResult - tail) / 10 != result)
51+ // { return 0; }
52+ // result = newResult;
53+ // x = x / 10;
54+ // }
55+
56+ // return result;
57+ // }
Original file line number Diff line number Diff line change 1+ /**
2+ * From the following table, find the highest roman numeral (n) with the highest decimal value (v)
3+ * that is taken from the left part of the roman numeral r
4+ *
5+ * From http://www.rapidtables.com/convert/number/how-roman-numerals-to-number.htm
6+ *
7+ * I 1
8+ * IV 4
9+ * V 5
10+ * IX 9
11+ * X 10
12+ * XL 40
13+ * L 50
14+ * XC 90
15+ * C 100
16+ * CD 400
17+ * D 500
18+ * CM 900
19+ * M 1000
20+ * res.js
21+ * @authors Your Name (you@example.org)
22+ * @date 2017-02-21 22:06:00
23+ * @version $Id$
24+ */
25+
26+ /**
27+ * @param {string } s
28+ * @return {number }
29+ */
30+ var romanToInt = function ( s ) {
31+ let res = 0 ;
32+ while ( s ) {
33+ if ( s . indexOf ( 'M' ) === 0 ) {
34+ res += 1000 ;
35+ s = s . substring ( 1 ) ;
36+ } else if ( s . indexOf ( 'CM' ) === 0 ) {
37+ res += 900 ;
38+ s = s . substring ( 2 ) ;
39+ } else if ( s . indexOf ( 'D' ) === 0 ) {
40+ res += 500 ;
41+ s = s . substring ( 1 ) ;
42+ } else if ( s . indexOf ( 'CD' ) === 0 ) {
43+ res += 400 ;
44+ s = s . substring ( 2 ) ;
45+ } else if ( s . indexOf ( 'C' ) === 0 ) {
46+ res += 100 ;
47+ s = s . substring ( 1 ) ;
48+ } else if ( s . indexOf ( 'XC' ) === 0 ) {
49+ res += 90 ;
50+ s = s . substring ( 2 ) ;
51+ } else if ( s . indexOf ( 'L' ) === 0 ) {
52+ res += 50 ;
53+ s = s . substring ( 1 ) ;
54+ } else if ( s . indexOf ( 'XL' ) === 0 ) {
55+ res += 40 ;
56+ s = s . substring ( 2 ) ;
57+ } else if ( s . indexOf ( 'X' ) === 0 ) {
58+ res += 10 ;
59+ s = s . substring ( 1 ) ;
60+ } else if ( s . indexOf ( 'IX' ) === 0 ) {
61+ res += 9 ;
62+ s = s . substring ( 2 ) ;
63+ } else if ( s . indexOf ( 'V' ) === 0 ) {
64+ res += 5 ;
65+ s = s . substring ( 1 ) ;
66+ } else if ( s . indexOf ( 'IV' ) === 0 ) {
67+ res += 4 ;
68+ s = s . substring ( 2 ) ;
69+ } else if ( s . indexOf ( 'I' ) === 0 ) {
70+ res += 1 ;
71+ s = s . substring ( 1 ) ;
72+ }
73+ }
74+
75+ return res ;
76+ } ;
You can’t perform that action at this time.
0 commit comments