Last active
April 13, 2021 05:35
-
-
Save KingAshiru/80f4d8682d8c762ec5e73e04ea1c2ff8 to your computer and use it in GitHub Desktop.
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
class Solution: | |
def removeDuplicates(self, nums): | |
#check for cases of an empty array | |
if len(nums) == 0: | |
return 0 | |
nextNonDuplicate = 1 | |
i = 1 | |
#since the array is sorted, all duplicates would be adjacent, | |
#so we start from the first element and check if the next element isn't a duplicate | |
#if it isn't, we update the array in-place using the index | |
while i < len(nums): | |
if nums[nextNonDuplicate - 1] != nums[i]: | |
nums[nextNonDuplicate] = nums[i] | |
nextNonDuplicate += 1 | |
i += 1 | |
return nextNonDuplicate |
Hi @meekg33k thanks for the feedback, I really appreciate that you took out
time to give feedback on my solution.
If you look closely at my code at the beginning part, I took into
consideration that I might have an edge case such as an empty array or null
value array,
I think you might have missed that, kindly look closely.
Again thanks for the feedback, it's much appreciated.
…On Mon, Apr 12, 2021 at 8:36 AM meekg33k ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
This is a really good solution @KingAshiru <https://github.com/KingAshiru>
and thanks for participating in Week 1 of Algorithm Fridays. I really like
that you updated the array in-place making your solution memory-optimal.
The only assumption your solution has made is that the input array cannot
have a null value because if I pass a None value as input to your code,
it breaks. Ideally, you want to write code that is robust and doesn't fail
on edge cases.
I have posted my solution here
<https://meekg33k.dev/how-to-find-the-number-of-unique-elements-in-a-sorted-array>,
let me know what you think.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/80f4d8682d8c762ec5e73e04ea1c2ff8#gistcomment-3702295>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMLPOL345WAQCPJ5GBVLWY3TIKPHXANCNFSM42YWQCLA>
.
Hey @meekg33k, on another look at my code, I think get what you mean, I
made the assumption I would always be provided an array.
Nice for you to point this isn't best for a robust code, I never really
paid attention to that when solving DSA questions,
now that you've pointed it out, I would always consider that moving forward.
I took a look at your solution and I think it's perfect in terms of memory,
time, and edge cases.
Cheers!
…On Mon, Apr 12, 2021 at 10:07 AM Tobi Ashiru ***@***.***> wrote:
Hi @meekg33k thanks for the feedback, I really appreciate that you took
out time to give feedback on my solution.
If you look closely at my code at the beginning part, I took into
consideration that I might have an edge case such as an empty array or null
value array,
I think you might have missed that, kindly look closely.
Again thanks for the feedback, it's much appreciated.
On Mon, Apr 12, 2021 at 8:36 AM meekg33k ***@***.***> wrote:
> ***@***.**** commented on this gist.
> ------------------------------
>
> This is a really good solution @KingAshiru
> <https://github.com/KingAshiru> and thanks for participating in Week 1
> of Algorithm Fridays. I really like that you updated the array in-place
> making your solution memory-optimal.
>
> The only assumption your solution has made is that the input array cannot
> have a null value because if I pass a None value as input to your code,
> it breaks. Ideally, you want to write code that is robust and doesn't fail
> on edge cases.
>
> I have posted my solution here
> <https://meekg33k.dev/how-to-find-the-number-of-unique-elements-in-a-sorted-array>,
> let me know what you think.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://gist.github.com/80f4d8682d8c762ec5e73e04ea1c2ff8#gistcomment-3702295>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AMLPOL345WAQCPJ5GBVLWY3TIKPHXANCNFSM42YWQCLA>
> .
>
Awesome and thanks for walking through the feedback @KingAshiru.
See you on Friday!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a really good solution @KingAshiru and thanks for participating in Week 1 of Algorithm Fridays. I really like that you updated the array in-place making your solution memory-optimal.
The only assumption your solution has made is that the input array cannot have a
null
value because if I pass aNone
value as input to your code, it breaks. Ideally, you want to write code that is robust and doesn't fail on edge cases.I have posted my solution here, let me know what you think.