Skip to content

Instantly share code, notes, and snippets.

@LordRahl90
Last active November 16, 2019 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LordRahl90/f05eb6b0bd985630125032ba10cfd268 to your computer and use it in GitHub Desktop.
Save LordRahl90/f05eb6b0bd985630125032ba10cfd268 to your computer and use it in GitHub Desktop.
Odd Occurrence in Array Solution in php
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;
}
@dirar
Copy link

dirar commented Nov 16, 2019

Hi, no need to continue checking the array, first occurrence is enough

@LordRahl90
Copy link
Author

Hi, no need to continue checking the array, first occurrence is enough

True... .Nice catch. Thanks, I don't even know why I decided to traverse the entire length of the array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment