leetcode new problems

This commit is contained in:
2026-02-11 14:48:41 +05:30
parent 192ce44a81
commit 0f52d46c67
29 changed files with 658 additions and 5 deletions
+25
View File
@@ -0,0 +1,25 @@
class Solution{
public:
int removeDuplicates(vector<int> & nums){
if(nums.empty()) return 0;
int i =1;
for(int j =1;j<nums.size();j++){
if(nums[j]!=nums[i-1]){
nums[i] = nums[j];
i++;
}
}
return i;
}
};
//TC : O(n)
//SC: O(1)
/* InPlace algorithm : An algorithm that modifies the input data directly, uses constant space o(1). Here We traverse the sorted array and keep only unique elements by overwriting duplicates in-place.
Whenever a new (different) element is found, we place it at the next available position.
The final count of unique elements is returned.
i -> marks the position where the next unique element should be stored
j-> scans the array to find new elements
*/