Skip to content

Instantly share code, notes, and snippets.

@mailopl
Created March 19, 2013 11:38
Show Gist options
  • Save mailopl/5195439 to your computer and use it in GitHub Desktop.
Save mailopl/5195439 to your computer and use it in GitHub Desktop.
Some codility task I solved
<?php
function maxProfit($A) {
$maxProfit = 0;
for ($P = 0, $N = count($A); $P < $N; ++$P) {
for ($Q = $P; $Q < $N; ++$Q) {
if (
$A[$Q] >= $A[$P] &&
$A[$Q] - $A[$P] > $maxProfit
) {
$maxProfit = $A[$Q] - $A[$P];
}
}
}
return $maxProfit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment