TizzyT

AlmostIncreasingSeqeunce -TizzyT

Sep 25th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1.         static bool AlmostIncreasingSeqeunce(int[] Sequence)
  2.         {
  3.             if (Sequence.Length < 3) return true;
  4.             int i1 = 0, i2 = Sequence.Length - 1;
  5.             for (; i1 < Sequence.Length && Sequence[i1] < Sequence[i1 + 1]; i1++) ;
  6.             for (; i2 > 0 && Sequence[i2] > Sequence[i2 - 1]; i2--) ;
  7.             if (Math.Abs(i1 - i2) > 1) return false;
  8.             else if (i1 > 0) return Sequence[i1 - 1] < Sequence[i2];
  9.             return true;
  10.         }
Advertisement
Add Comment
Please, Sign In to add comment