g0201_0300.s0283_move_zeroes.complexity.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java21 Show documentation
Show all versions of leetcode-in-java21 Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
**Time Complexity (Big O Time):**
The time complexity of this program is O(n), where 'n' is the length of the input array `nums`. This is because the program iterates through the entire array exactly once in a single pass. The loop runs 'n' times, and inside the loop, there are constant-time operations such as checking and swapping elements.
**Space Complexity (Big O Space):**
The space complexity of the program is O(1), which indicates constant space usage. Regardless of the size of the input array, the program only uses a constant amount of extra space to store integer variables (`firstZero`, `i`, and `val2`) and does not use any additional data structures whose space requirements depend on the input size. The space used for these variables remains constant.
In summary, the provided program has a time complexity of O(n), where 'n' is the length of the input array `nums`, and it has a space complexity of O(1), indicating constant space usage.