DekGenius.com
JAVA
Remove Duplicates from Sorted Array
public int RemoveDuplicates(int[] nums)
{
int i=0,j=1;
while(j<nums.Length)nums[++i]=nums[j++]==nums[--i] ? nums[i]:nums[j+i-++i];
return i+1;
}
i am freindly code below
public class Solution
{
public int RemoveDuplicates(int[] nums)
{
int i=0,j=1;
while(j<nums.Length)
{
if(nums[j]==nums[i]) j++;
else nums[++i] =nums[j++];
}
return i+1;
}
}
remove duplicates from sorted array
// Java
public int removeDuplicates(int[] nums) {
if (nums.length == 0) return 0;
int i = 0;
for (int j = 1; j < nums.length; j++) {
if (nums[j] != nums[i]) {
i++;
nums[i] = nums[j];
}
}
return i + 1;
}
remove duplicates from sorted array
def remove_duplicates(nums: [int]) -> int:
cnt = 1
for index in range(len(nums) - 1):
if nums[index] != nums[index + 1]:
nums[cnt] = nums[index + 1]
cnt += 1
print(cnt)
remove duplicates from sorted array
def remove_duplicate(nums: [int]) -> int:
nums[:] = sorted(set(nums))
return len(nums)
remove duplicates from sorted list solution in c++
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if(head == NULL || head->next == NULL)
return head;
ListNode* temp=head;
ListNode* cur=head->next;
while(cur!=NULL)
{
if(cur->val==temp->val)
{
temp->next=cur->next;
}else
{
temp=cur;
}
cur=cur->next;
}
return head;
}
};
Remove Duplicates from Sorted Array
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
}
};
Remove Duplicates from Sorted Array
class Solution {
public int removeDuplicates(int[] nums) {
}
}
Remove Duplicates from Sorted Array
int removeDuplicates(int* nums, int numsSize){
}
Remove Duplicates from Sorted Array
public class Solution {
public int RemoveDuplicates(int[] nums) {
}
}
Remove Duplicates from Sorted Array
/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function(nums) {
};
Remove Duplicates from Sorted Array
# @param {Integer[]} nums
# @return {Integer}
def remove_duplicates(nums)
end
Remove Duplicates from Sorted Array
class Solution {
func removeDuplicates(_ nums: inout [Int]) -> Int {
}
}
Remove Duplicates from Sorted Array
class Solution {
/**
* @param Integer[] $nums
* @return Integer
*/
function removeDuplicates(&$nums) {
}
}
Remove Duplicates from Sorted Array
function removeDuplicates(nums: number[]): number {
};
© 2022 Copyright:
DekGenius.com