You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 3sum/evan.js
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -47,3 +47,14 @@ var threeSum = function (nums) {
47
47
48
48
returnresult;
49
49
};
50
+
51
+
/**
52
+
* Time Complexity: O(n^2)
53
+
* The algorithm involves sorting the input array, which takes O(n log n) time.
54
+
* The main part of the algorithm consists of a loop that runs O(n) times, and within that loop, there is a two-pointer technique that runs in O(n) time.
55
+
* Thus, the overall time complexity is O(n log n) + O(n^2), which simplifies to O(n^2).
56
+
*
57
+
* Space Complexity: O(n)
58
+
* The space complexity is O(n) due to the space needed for the sorted array and the result array.
59
+
* Although the sorting algorithm may require additional space, typically O(log n) for the in-place sort in JavaScript, the dominant term is O(n) for the result storage.
0 commit comments