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

Commit4d55fcf

Browse files
committed
update
1 parent9c00510 commit4d55fcf

File tree

4 files changed

+168
-1
lines changed

4 files changed

+168
-1
lines changed

‎README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
This 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|

‎src/customers-who-never-order/res.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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);

‎src/reverse-integer/res.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
varreverse=function(x){
21+
letres=0,
22+
abs=Math.abs(x),
23+
negative=abs===x?false:true;
24+
25+
while(abs>0){
26+
letcurrentVal=abs%10;
27+
res=res*10+currentVal;
28+
abs=Number.parseInt(abs/10);
29+
}
30+
31+
if(res>Math.pow(2,31)){
32+
return0;
33+
}elseif(negative){
34+
return-res;
35+
}
36+
37+
returnres;
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+
// }

‎src/roman-to-integer/res.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
* I1
8+
* IV4
9+
* V5
10+
* IX9
11+
* X10
12+
* XL40
13+
* L50
14+
* XC90
15+
* C100
16+
* CD400
17+
* D500
18+
* CM900
19+
* M1000
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+
varromanToInt=function(s){
31+
letres=0;
32+
while(s){
33+
if(s.indexOf('M')===0){
34+
res+=1000;
35+
s=s.substring(1);
36+
}elseif(s.indexOf('CM')===0){
37+
res+=900;
38+
s=s.substring(2);
39+
}elseif(s.indexOf('D')===0){
40+
res+=500;
41+
s=s.substring(1);
42+
}elseif(s.indexOf('CD')===0){
43+
res+=400;
44+
s=s.substring(2);
45+
}elseif(s.indexOf('C')===0){
46+
res+=100;
47+
s=s.substring(1);
48+
}elseif(s.indexOf('XC')===0){
49+
res+=90;
50+
s=s.substring(2);
51+
}elseif(s.indexOf('L')===0){
52+
res+=50;
53+
s=s.substring(1);
54+
}elseif(s.indexOf('XL')===0){
55+
res+=40;
56+
s=s.substring(2);
57+
}elseif(s.indexOf('X')===0){
58+
res+=10;
59+
s=s.substring(1);
60+
}elseif(s.indexOf('IX')===0){
61+
res+=9;
62+
s=s.substring(2);
63+
}elseif(s.indexOf('V')===0){
64+
res+=5;
65+
s=s.substring(1);
66+
}elseif(s.indexOf('IV')===0){
67+
res+=4;
68+
s=s.substring(2);
69+
}elseif(s.indexOf('I')===0){
70+
res+=1;
71+
s=s.substring(1);
72+
}
73+
}
74+
75+
returnres;
76+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp