bill.z.li
BAN USER/// @param a the array containing the numbers we are checking
/// @param indices[out] The indices(inclusive) the function will return
/// @return true if the finding is successful, false otherwise
bool find(const vector<int>& a, pair<int, int>& indies)
{
if (a.empty()) return false;
indies.first = 0;
indies.second = 0;
for (int i = 0, j = 0; j < a.size(); ++j)
{
if (a[j] > a[j - 1])
{
if (j - i > indies.second - indies.first)
{
indies.first = i;
indies.second = j;
}
}
else
{
i = j;
}
}
return true;
}
If you want a short Python code:
But in big O term, it is not best.
- bill.z.li March 21, 2013