0
How to remove redundant array values ..?
I have an array arr=[1,2,3,3,4,4,5,5,6] i need to remove the duplicates values of the array arr. how ?
6 ответов
+ 7
Techie Praga, this is a place to ask questions and answer other people's questions. It isn't meant to answer your own questions and give yourself the best answer. By the way, your code is incomplete.
https://www.sololearn.com/Discuss/1316935/welcome-to-sololearn-forum/
You can advertise your codes here:
https://www.sololearn.com/Discuss/452626/off-topic-code-advertising
+ 5
You could also try to transfer the values of the array to a set. The set will only store the unique values of the array.
+ 3
My proposition 😊
// short and simple solution
https://code.sololearn.com/c880WSnCyPFz/?ref=app
+ 1
// simple java program to remove duplicates array values.
// techie praga codes
class Main
{
// Function
// This function- removeDuplicates (to remove duplicate elements)returns new size of modified array
static int removeDuplicates(int arr[], int n)
{
if (n == 0 || n == 1)
return n;
// To store index of next unique element
int j = 0;
// Doing same as done in Method 1
// Just maintaining another updated index i.e. j
for (int i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j++] = arr[i];
arr[j++] = arr[n-1];
return j;
}
public static void main (String[] args)
{
int arr[] = {1, 2, 2, 3, 4, 4, 4, 5, 5};
int n = arr.length;
n = removeDuplicates(arr, n);
// Print updated array
for (int i=0; i<n; i++)
System.out.prin
0
sir could you pls tell me how to learn *all* programming langs without practicing in 1day😀
0
tnx for ur suggestions, btw (we solve our some prgms here)and share the link to our frnds who are willing to learn java