-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49385a8
commit cffc3bd
Showing
8 changed files
with
84 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,39 @@ | ||
/** | ||
* Definition for singly-linked list. | ||
* function ListNode(val, next) { | ||
* this.val = (val===undefined ? 0 : val) | ||
* this.next = (next===undefined ? null : next) | ||
* } | ||
*/ | ||
/** | ||
* @param {ListNode[]} lists | ||
* @return {ListNode} | ||
*/ | ||
var mergeKLists = function(lists) { | ||
const mergeTwoLists = (l1, l2) => { | ||
if (!l1 || !l2) return l1 || l2 | ||
let listNode = new ListNode | ||
let cur = listNode | ||
while(l1 && l2) { | ||
if(l1.val > l2.val) { | ||
cur.next = l2 | ||
l2 = l2.next | ||
} else { | ||
cur.next = l1 | ||
l1 = l1.next | ||
} | ||
cur = cur.next | ||
} | ||
cur.next = l1 || l2 | ||
return listNode.next | ||
} | ||
|
||
let root = lists[0]; | ||
for (let i = 1; i < lists.length; i++) { | ||
root = mergeTwoLists(root, lists[i]); | ||
} | ||
|
||
return root || null; | ||
}; | ||
|
||
// leetcode 0023 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
// leetcode 0230 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
// leetcode 695 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
// Input: "CABADCBD" | ||
// Output: "" | ||
// Explanation: "CABADCBD" -> "CADCBD" -> "CABD" -> "CD" -> "" | ||
|
||
// Input: "ACBD" | ||
// Output: "ACBD" | ||
// Explanation: "A" 和 "B" 以及 "C" 和 "D" 均沒有相鄰,無法轉態 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @param {string} s | ||
* @return {boolean} | ||
*/ | ||
var isPalindrome = function(s) { | ||
let str = s | ||
.toLowerCase() | ||
.replace(/[^a-z0-9]/g, '') | ||
|
||
let left = 0 | ||
let right = str.length - 1 | ||
while (left <= right) { | ||
if (str[left] !== str[right]) { | ||
return false | ||
} | ||
left++ | ||
right-- | ||
} | ||
return true | ||
}; | ||
|
||
// 2022/05/11 done. | ||
// Runtime: 110 ms, faster than 36.67% of JavaScript online submissions for Valid Palindrome. | ||
// Memory Usage: 44.2 MB, less than 82.99% of JavaScript online submissions for Valid Palindrome. |
This file was deleted.
Oops, something went wrong.