Like many people who have been on the internet for more than 5 years, I have been burdened with an outdated email address for some time now. This is a common problem, whether it be something as embarrassing as an email ending “@aol.com”, or one of the equally common teenage-years…
A few months back, I entered the crazy world of LeetCode.
What is LeetCode
For those of you who don’t know, LeetCode is a site that posts thousands of coding problems at varying difficulties, and asks you to solve them, whilst providing various test cases that your solution must pass. …
In the world of programming, there are many ways to sort data. For the average engineer, you might just use .sort(), perhaps with a slightly modified sorting function to return your data in a specific way But that’s probably about the most you do.
In this LeetCode problem, we’re asked to delete a node from a Linked List. However, we aren’t given the Linked List’s head, and are instead provided with the node that needs to be deleted.
To be honest, this question is a little too simple. Thanks to the question guaranteeing that you won’t be given the tail node of a Linked List, there aren’t even any edge cases to handle, so the solution comes in at a whopping 2 lines.
Solution #1: Replace the node with the next one
This incredibly simple solution simply replace the to-be-deleted node’s value with the next one in the Linked List, as well as the next value also. This technically deletes the next node in the list after copying its contents, but in doing so achieves the original goal of deleting the supplied node.
In this LeetCode problem, we’re given what is arguably the best known programming challenge out there: FizzBuzz. For those few of you who have never heard of such a thing, the idea is to create a function that will count from 1 to N (N being a number provided to…