The important thing is your code works. Well done! I solved this differently than you did, but your way is just as valid.
At this point, in my opinion, it’s fine to just be happy with solving the algorithm. It can be useful to come back to the basic algorithms and redo them in a few weeks, or a month. Refactoring your code on your own after learning more is great practice.
Oh, by the way, you should probably use the spoiler function when posting full solutions. They don’t like too many solutions for the challenges in the forum.