-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b32bc03
commit 83526e3
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.5.0 <0.9.0; | ||
|
||
contract Day4 { | ||
//Create a function distinct(array, length of array) | ||
//This distinct() will take two arguments - a dynamic uint type array and length of the array. | ||
//The distinct() will return the number of distinct elements in an array. | ||
function distinct(int256[] memory array, uint256 len) | ||
public | ||
pure | ||
returns (uint256) | ||
{ | ||
uint256 i; | ||
uint256 j; | ||
uint256 count = 1; | ||
|
||
for (i = 1; i < len; i++) { | ||
for (j = 0; j < i; j++) { | ||
if (array[i] == array[j]) { | ||
break; | ||
} | ||
} | ||
if (i == j) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
} |