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

Commit3e2d885

Browse files
committed
update: 2 solutions
1 parent0c7986f commit3e2d885

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

‎README.md

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

33
This is the solution collection of my LeetCode problems, most of them are programmed in JavaScript.
44

5-
Progress:9/
5+
Progress:12/
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+
|66|[Plus One](https://leetcode.com/problems/plus-one/)|[JavaScript](./src/plus-one/res.js)|Easy|
1112
|175|[Combine Two Tables](https://leetcode.com/problems/combine-two-tables/)|[SQL](./src/combine-two-tables/res.txt)|Easy|
1213
|176|[Second Highest Salary](https://leetcode.com/problems/second-highest-salary/)|[SQL](./src/second-highest-salary/res.txt)|Easy|
1314
|177|[Nth Highest Salary](https://leetcode.com/problems/nth-highest-salary/)|[SQL](./src/nth-highest-salary/res.txt)|Medium|
1415
|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|
1516
|182|[Duplicate Emails](https://leetcode.com/problems/duplicate-emails/)|[SQL](./src/duplicate-emails/res.txt)|Easy|
1617
|184|[Department Highest Salary](https://leetcode.com/problems/department-highest-salary/)|[SQL](./src/department-highest-salary/res.txt)|Medium|
1718
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/)|[SQL](./src/rising-temperature/res.txt)|Easy|
19+
|342|[Power of Four](https://leetcode.com/problems/power-of-four/)|[JavaScript](./src/power-of-four/res.js)|Easy|
1820
|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/plus-one/res.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
3+
*
4+
* You may assume the integer do not contain any leading zero, except the number 0 itself.
5+
*
6+
* The digits are stored such that the most significant digit is at the head of the list.
7+
*
8+
* res.js
9+
*@authors Joe Jiang (hijiangtao@gmail.com)
10+
*@date 2017-02-18 19:41:09
11+
*@version $Id$
12+
*/
13+
14+
/**
15+
*@param {number[]} digits
16+
*@return {number[]}
17+
*/
18+
letplusOne=function(digits){
19+
letcarrybit=1,
20+
res=[];
21+
22+
for(leti=digits.length-1;i>=0;i--){
23+
letcurrentval=digits[i]+carrybit;
24+
if(currentval>9){
25+
carrybit=1;
26+
currentval%=10;
27+
}else{
28+
carrybit=0;
29+
}
30+
res.unshift(currentval)
31+
}
32+
33+
if(carrybit===1){
34+
res.unshift(1);
35+
}
36+
37+
returnres;
38+
};

‎src/power-of-four/res.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
3+
*
4+
* Example:
5+
*
6+
* Given num = 16, return true. Given num = 5, return false.
7+
*
8+
* Follow up: Could you solve it without loops/recursion?
9+
*
10+
* Hint: We know that if number is power of two, it satisfies that n & (n – 1) equals zero, that is: n & (n – 1) removes the least significant bit, leaving the number (that is power of two) zero. We also know that mathematically, 4^n - 1 can be divided by 3.
11+
*
12+
*@authors Joe Jiang (hijiangtao@gmail.com)
13+
*@date 2017-02-18 20:13:10
14+
*@version $Id$
15+
*/
16+
17+
/**
18+
*@param {number} num
19+
*@return {boolean}
20+
*/
21+
letisPowerOfFour=function(num){
22+
letcompNum=num-1;
23+
if(num<1||num&compNum){
24+
returnfalse;
25+
}
26+
if(compNum%3!==0){
27+
returnfalse;
28+
}
29+
30+
returntrue;
31+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp