Last active
November 16, 2019 09:07
-
-
Save LordRahl90/f05eb6b0bd985630125032ba10cfd268 to your computer and use it in GitHub Desktop.
Odd Occurrence in Array Solution in php
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
function solution($A) { | |
// write your code in PHP7.0 | |
$values=array_count_values($A); | |
foreach($values as $key=>$value){ | |
if(($value % 2===1)){ | |
return $key | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
True... .Nice catch. Thanks, I don't even know why I decided to traverse the entire length of the array.