diff --git a/src/main/java/ru/code/eight/RemoveDuplicates.java b/src/main/java/ru/code/eight/RemoveDuplicates.java new file mode 100644 index 0000000..8abd9b9 --- /dev/null +++ b/src/main/java/ru/code/eight/RemoveDuplicates.java @@ -0,0 +1,16 @@ +package ru.code.eight; + + +public class RemoveDuplicates { + public static int removeDuplicates(int[] a) { + int result = 0; + for (int i = 0; i < a.length; i++) { + if (a[i] != a[result]) { + result++; + a[result] = a[i]; + } + } + return result + 1; + + } +} diff --git a/src/test/java/ru/code/eight/RemoveDuplicatesTest.java b/src/test/java/ru/code/eight/RemoveDuplicatesTest.java new file mode 100644 index 0000000..e6a542c --- /dev/null +++ b/src/test/java/ru/code/eight/RemoveDuplicatesTest.java @@ -0,0 +1,12 @@ +package ru.code.eight; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class RemoveDuplicatesTest { + @Test + void removeDuplicates() { + assertThat(5).isEqualTo(RemoveDuplicates.removeDuplicates(new int[]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4})); + } +} \ No newline at end of file