From ee47e1ccc80db6d4fd0554b7d31e4fce32f58bed Mon Sep 17 00:00:00 2001 From: Rupa <102663541+Rupa-Rd@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:15:57 +0000 Subject: [PATCH] Sync LeetCode submission - Remove Duplicates from Sorted Array (java) --- .../solution.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 my-folder/problems/remove_duplicates_from_sorted_array/solution.java diff --git a/my-folder/problems/remove_duplicates_from_sorted_array/solution.java b/my-folder/problems/remove_duplicates_from_sorted_array/solution.java new file mode 100644 index 0000000..12bffd4 --- /dev/null +++ b/my-folder/problems/remove_duplicates_from_sorted_array/solution.java @@ -0,0 +1,15 @@ +class Solution { + public int removeDuplicates(int[] nums) { + int i = 0, j = 1; + + while(j < nums.length){ + if(nums[j] != nums[j - 1]){ + nums[++ i] = nums[j]; + } + j ++; + } + + + return i + 1; + } +} \ No newline at end of file