Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitscript authored Sep 28, 2022
1 parent b32bc03 commit 83526e3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 16Day-DistinctElements.sol
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;
}
}

0 comments on commit 83526e3

Please sign in to comment.