Finding duplicate elements
vino
akashvino79 at gmail.com
Sun Aug 27 06:12:57 UTC 2023
On Wednesday, 16 August 2023 at 12:51:31 UTC, FeepingCreature
wrote:
> On Tuesday, 15 August 2023 at 17:59:27 UTC, vino wrote:
>> [...]
>
> ```
> import std;
> void main() {
> string[] args = [" test3", "test2 ", " test1 ", " test1 ",
> " "];
> findDuplicates(args);
> }
> void findDuplicates(string[] args) {
> bool[string] dupes;
> foreach (arg; args) {
> if (arg in dupes) {
> writefln!"Duplicate element found: %s"(arg);
> return;
> }
> dupes[arg] = true;
> }
> writefln!"%s"(dupes.keys);
> }
> ```
Thank you very much
More information about the Digitalmars-d-learn
mailing list