Skip to content

Commit 47c0cfa

Browse files
committed
add: Two submissions
1 parent 35ec129 commit 47c0cfa

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
| ID | Title | Solution | Difficulty |
44
|---| ----- | -------- | ---------- |
5-
|1|[Two Sum](https://leetcode.com/problems/two-sum/) | [JavaScript](./src/two-sum.js)|Easy|
6-
|434|[Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string/) | [JavaScript](./src/number-of-segments-in-a-string.js)|Easy|
5+
|1|[Two Sum](https://leetcode.com/problems/two-sum/) | [JavaScript](./src/two-sum/res.js)|Easy|
6+
|2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [JavaScript](./src/add-two-numbers/res.js)|Medium|
7+
|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|
8+
|434|[Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string/) | [JavaScript](./src/number-of-segments-in-a-string/res.js)|Easy|

src/add-two-numbers/res.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Add Two Numbers
3+
* @authors Joe Jiang (hijiangtao@gmail.com)
4+
* @date 2017-02-15 20:52:23
5+
*
6+
* You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
7+
*
8+
* You may assume the two numbers do not contain any leading zero, except the number 0 itself.
9+
*
10+
* Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
11+
*
12+
* Output: 7 -> 0 -> 8
13+
*/
14+
15+
/**
16+
* Definition for singly-linked list.
17+
* function ListNode(val) {
18+
* this.val = val;
19+
* this.next = null;
20+
* }
21+
*/
22+
/**
23+
* @param {ListNode} l1
24+
* @param {ListNode} l2
25+
* @return {ListNode}
26+
*/
27+
let addTwoNumbers = function(l1, l2) {
28+
let currentAddVal = l1.val+l2.val,
29+
res = new ListNode( currentAddVal % 10 ),
30+
increment = currentAddVal > 9 ? 1:0;
31+
32+
if (l1.next !== null && l2.next !== null) {
33+
let nextl1 = ListNode(l1.next.val+increment);
34+
nextl1.next = l1.next.next;
35+
res.next = new ListNode(nextl1, l2.next)
36+
} else if (l1.next === null) {
37+
let nextl1 = new ListNode(increment);
38+
res.next = increment + addTwoNumbers(nextl1, l2.next)
39+
return res
40+
} else if (l2.next === null) {
41+
let nextl2 = new ListNode(increment);
42+
res.next = addTwoNumbers(nextl2, l1.next)
43+
} else if (increment) {
44+
res.next = new ListNode(increment);
45+
}
46+
47+
return convertToArray(res);
48+
};
49+
50+
let convertToArray = function(LN) {
51+
let res = []
52+
for (;;) {
53+
if (LN.next === null) {
54+
return res;
55+
} else {
56+
res.push(LN.val);
57+
LN = LN.next;
58+
}
59+
}
60+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write your MySQL query statement below
2+
SELECT a.Name AS "Employee" FROM Employee a inner join Employee b ON a.ManagerId = b.Id AND a.Salary > b.Salary
File renamed without changes.

0 commit comments

Comments
 (0)