menu
davidfarley7171
Do one problem on leetcode everyday... Star this Commitment
Day 19 of 19

davidfarley7171 commits to:
Submit 1 problem on leetcode every day, or until I get a job.
17
2
No more reports due
Details
My Commitment Journal
davidfarley7171
davidfarley7171
May 20, 2020, 12:30 AM
# 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.

Make two pointers called start and end set to the start index, and the end index.
Loop throug the array, if the value at current index is red, swap it with start and increment both,
if the value at current index is blue, swap with last end index, decrement end index and increment current index.
If its white, increment the current index
davidfarley7171
davidfarley7171
May 19, 2020, 2:26 AM
/ basically in javascript you store the heap in an array.
// the way you do this is by following this rule
// left child: i * 2
// right child: i * 2 + 1
// parent: i / 2

// to insert you add a new value to the end of the array, check if its smaller than its parent, if so then you move it up by swapping it with the parent, then check again.
//Each time you need to check to see if you have reached the first index of the array. Or if the next value is the first index of the array, if so stop. Else make the current index which is the child, the index of the parent.

// to remove its more complicated. but simlar concept.
//you are going to remove the root because its always the smallest. Remove it, and swap the very last element of the array with the very first.
//if the length is 2, remove the first value, and move the seoncd into the first place.
//if the length is 3, swap the new root with the smaller of the children you are good
//else, use a while loop. use the formula to get the right and left children,
// while the value at the index is greater than either of its children, swap it with its smaller child. Then set the index to that of the child.
//lastly, if either of the new children are undefined, then break. Else continue the loop.
// lastly return the smallest value you removed at the beginning.
davidfarley7171
davidfarley7171
May 18, 2020, 4:48 PM
These last 3 days Im not going to do.
I need to focus on finishing up preparation for my teaching class, and then ill come back to this and start a new commitment or something.
davidfarley7171
davidfarley7171
May 17, 2020, 3:29 PM
I actually did not yesterday but I was too buzy so im gonna give myself a pass
    This Commitment has no photos.
Displaying 1-4 of 19 results.
May 19
Not Successful
No report submitted
No report submitted
May 18
Successful (referee feedback expired)
Success
No report submitted
May 17
Successful (referee feedback expired)
Success
No report submitted
May 16
Successful (referee feedback expired)
Success
No report submitted
Recipient of Stakes
Anti-charity (Animal Rights: People for the Ethical Treatment of Animals (PETA))
To change the Recipient of Stakes for your Do one problem on leetcode everyday... Commitment, enter their email address or stickK username below.
Total at stake: $95.00
Stakes per period: $5.00
Remaining Stakes: $0.00
Total Money Lost: $10.00
Referee
Supporters
This Commitment doesn't have any Supporters yet!
.
+
Server IP 10.0.0.173
Portal Id 0
User Id 0
Unix Timestamp 1714915272
Current Timezone GMT
Server encoding: utf-8
Assets folder: https://static.stickk.com/yii-assets/dcbc9e4e
Payment Type PRODUCTION
Your feedback has been sent. Thank you!
This website uses cookies to ensure you get the best experience on our website. Read our Privacy Policy
Loading...