Explaining Leetcode -

Опубликовано: 03 Март 2026
на канале: JTECH
26
0

In this video I explain the algorithm behind solving Leetcode problem 905 Sort Array By Parity. I first solve the problem using two ArrayLists since I can't know beforehand the number of odd and even elements. I stream the lists into an array and return it. Then, I get rid of the stream hoping to make the code perform better.
I try then using array approach since I know the total number of elements (even without knowing how much are odd/even). It works well using two for loops, one to detect even elements and one to detect the odd ones. Finally, I modify the code to achieve the task with 0ms.
I am coding in Java since its syntax is easy to understand by all programmers. The algorithms can be applied easily in other languages and most functions that I use have a counterpart in your language of choice.

00:00 Introduction + solving using two lists
06:44 Replacing stream with a for loop
08:52 Solving using one array and two for loops
14:01 Using one array and one for loop