- Notifications
You must be signed in to change notification settings - Fork2.4k
Create 234-Palindrome-Linked-List.js#279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
neetcode-gh merged 4 commits intoneetcode-gh:mainfromsiddheshranade:siddheshranade-patch-1Jul 2, 2022
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
072fbaf Create 234-Palindrome-Linked-List.js
siddheshranadecf92ddb Create 160-Intersection-of-Two-Linked-Lists.js
siddheshranade4bb7671 Merge pull request #1 from siddheshranade/siddheshranade-patch-2
siddheshranade9798aa4 Create 35-Search-Insert-Position.js
siddheshranadeFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletionsjavascript/160-Intersection-of-Two-Linked-Lists.js
This file contains hidden or 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,23 @@ | ||
| /** | ||
| * Definition for singly-linked list. | ||
| * function ListNode(val) { | ||
| * this.val = val; | ||
| * this.next = null; | ||
| * } | ||
| */ | ||
| /** | ||
| * @param {ListNode} headA | ||
| * @param {ListNode} headB | ||
| * @return {ListNode} | ||
| */ | ||
| var getIntersectionNode = function(headA, headB) { | ||
| let a = headA; | ||
| let b = headB; | ||
| while (a !== b) { | ||
| a = a === null ? headB : a.next; | ||
| b = b === null ? headA : b.next; | ||
| } | ||
| return a; | ||
| }; |
43 changes: 43 additions & 0 deletionsjavascript/234-Palindrome-Linked-List.js
This file contains hidden or 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,43 @@ | ||
| /** | ||
| * Definition for singly-linked list. | ||
| * function ListNode(val, next) { | ||
| * this.val = (val===undefined ? 0 : val) | ||
| * this.next = (next===undefined ? null : next) | ||
| * } | ||
| */ | ||
| /** | ||
| * @param {ListNode} head | ||
| * @return {boolean} | ||
| */ | ||
| var isPalindrome = function(head) { | ||
| // find mid point | ||
| let slow = head; | ||
| let fast = head; | ||
| while (fast && fast.next) { | ||
| slow = slow.next; | ||
| fast = fast.next.next; | ||
| } | ||
| // reverse 2nd half | ||
| let curr = slow; | ||
| let prev = null; | ||
| while (curr) { | ||
| let next = curr.next; | ||
| curr.next = prev; | ||
| prev = curr; | ||
| curr = next; | ||
| } | ||
| let head2 = prev; | ||
| // compare both halfs | ||
| while (head && head2) { | ||
| if (head.val !== head2.val) { | ||
| return false; | ||
| } | ||
| head = head.next; | ||
| head2 = head2.next; | ||
| } | ||
| return true; | ||
| }; |
23 changes: 23 additions & 0 deletionsjavascript/35-Search-Insert-Position.js
This file contains hidden or 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,23 @@ | ||
| /** | ||
| * @param {number[]} nums | ||
| * @param {number} target | ||
| * @return {number} | ||
| */ | ||
| var searchInsert = function(nums, target) { | ||
| let left = 0; | ||
| let right = nums.length - 1; | ||
| while (left <= right) { | ||
| let midIdx = Math.floor((left + right) / 2); | ||
| if (target === nums[midIdx]) { | ||
| return midIdx; | ||
| } | ||
| if (target > nums[midIdx]) { | ||
| left = midIdx + 1; | ||
| } else { | ||
| right = midIdx - 1; | ||
| } | ||
| } | ||
| return left; | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.