Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
Example 1:
Given nums = [1,1,2],
Your function should return length =, with the first two elements of being and respectively.
It doesn't matter what you leave beyond the returned length.2nums12
Example 2:
Given nums = [0,0, 1,1,1,2,2,3,3,4],
Your function should return length =, with the first five elements of being modified to,,,, and respectively.
It doesn't matter what values are set beyond the returned length.
Main Problem is to correctly understand the problem < span style="font-size: 18px;">,when I first saw this function I see int is the return type. I only think it's need return the number of sum,but actually it also need to move vector variable The most unimaginable thing is this problem only see first-N variable.You needn't see the last of array,You even needn't delete them from your vector.Unimaginable But it also reflect that I'm not familiar with the method to delete from STL vector. Special Remind,In myfunction main function fo not watch(not matching) with the solution part.Main use to see the vector's constitute 5nums01234
Given a sorted array nums, remove the duplicates in-place such that each element appear only< em>once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the i nput array in-place with O(1) extra memory.
Example 1:
Given nums = [1,1,2],
Your function should return length =, with the first two elements of being and respectively.
It doesn't matter what you leave beyond the returned length.2nums12
Example 2:
Given nums = [0,0, 1,1,1,2,2,3,3,4],
Your function should return length =, with the first five elements of being modified to,,,, and respectively.
It doesn't matter what values are set beyond the returned length.
Main Problem is to correctly understand the problem < span style="font-size: 18px;">,when I first saw this function I see int is the return type. I only think it's need return the number of sum,but actually it also need to move vector variable The most unimaginable thing is this problem only see first-N variable.You needn't see the last of array,You even needn't delete them from your vector.Unimaginable But it also reflect that I'm not familiar with the method to delete from STL vector. Special Remind,In myfunction main function fo not watch(not matching) with the solution part.Main use to see the vector's constitute 5nums01234
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O (1) extra memory.
Example 1:
Given nums = [1,1,2],
Your function should return length =, with the first two elements of being and respectively.
It doesn't matter what you leave beyond the returned length.2nums12
Example 2:
Given nums = [0,0, 1,1,1,2,2,3,3,4],
Your function should return length =, with the first five elements of being modified to,,,, and respectively.
It doesn't matter what values are set beyond the returned length.
Main Problem is to correctly understand the problem < span style="font-size: 18px;">,when I first saw this function I see int is the return type. I only think it's need return the number of sum,but actually it also need to move vector variable The most unimaginable thing is this problem only see first-N variable.You needn't see the last of array,You even needn't delete them from your vector.Unimaginable But it also reflect that I'm not familiar with the method to delete from STL vector. Special Remind,In myfunction main function fo not watch(not matching) with the solution part.Main use to see the vector's constitute 5nums01234