g0101_0200.s0136_single_number.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-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
**Time Complexity (Big O Time):**
The program uses a single loop that iterates through all the elements of the `nums` array. Within each iteration, it performs a constant-time operation (XOR) on the current element and the result variable `res`. Therefore, the time complexity of this program is O(N), where N is the number of elements in the `nums` array. In other words, it has a linear time complexity because it processes each element once.
**Space Complexity (Big O Space):**
The program has a very low space complexity because it uses a constant amount of additional memory that doesn't depend on the size of the input `nums` array. It only uses a single integer variable `res` to store the result. Therefore, the space complexity of this program is O(1), indicating constant space usage.
In summary, the program has a time complexity of O(N), where N is the number of elements in the input array `nums`, and a space complexity of O(1), indicating that it uses a fixed amount of memory regardless of the size of the input.