Given an array of size n. Your task is to remove the duplicates from the array.
Input : array: 1 2 1 2 1 3 2 Output :1 2 3 Input :array: 10 24 5 10 24 Output :10 24 5
We will use two loops to solve this problem. The first loop i will traverse from 0 to the length of the array. The second loop will traverse from 0 to i-1. This loop is used to make sure that the element at index i has not come before i. If that element has come before, then we come out of the second loop. just after the second loop, we write an if condition which checks if j = = i. If they are equal, it means that the element at index i has not occurred before. So we must append the element to the result array.
[1 2 3]
- Golang program that removes duplicates, ignores order
- Golang Program that Removes Duplicate Elements From the Array
- PHP break (Single and Nested Loops)
- Why are elementwise additions much faster in separate loops than in a combined loop?
- Loops in Go Language
- ES6 | Loops
- Loops in R (for, while, repeat)
- Join operation Vs Nested query in DBMS
- Nested List Comprehensions in Python
- Go Decision Making (if, if-else, Nested-if, if-else-if)
- Decision Making in R Programming - if, if-else, if-else-if ladder, nested if-else, and switch
- Golang program that uses fallthrough keyword
- Golang Program that uses String Switch
- Golang Program that switch on floating-point numbers
- Golang program that uses structs as map keys
- Golang program that uses switch, multiple value cases
- Golang Program to Count Trailing Zeros in Factorial of a Number
- Golang Program to Find Largest Element in an Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.