Skip to content

Commit cab11cb

Browse files
changes made to #324
1 parent 36168b4 commit cab11cb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Arrays/add_reverse_integer.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ class Solution {
3434
}
3535
}
3636

37+
38+
/*
39+
40+
APPROACH: The reverse function takes an integer as input and returns the reversed integer. The function first initializes a variable to store the reversed integer and then iterates over each digit of the input integer. In each iteration, the function extracts the rightmost digit of the input integer, checks if multiplying the reversed integer by 10 and adding the rightmost digit will cause integer overflow or underflow, adds the rightmost digit to the reversed integer, and removes the rightmost digit from the input integer. Finally, the function returns the reversed integer.
41+
42+
Time Complexity:
43+
The time complexity of the reverse function is O(log(x)), where x is the input integer. This is because the function needs to iterate over each digit of the input integer, which is proportional to the logarithm of the integer.
44+
45+
Space Complexity:
46+
The space complexity of the reverse function is O(1), because it only uses a constant amount of additional space to store the reversed integer and the remainder.
47+
48+
*/

0 commit comments

Comments
 (0)