Skip to content

Instantly share code, notes, and snippets.

@David-Hackro
Last active October 24, 2018 22:00
Show Gist options
  • Save David-Hackro/b4d8722cce3297bc1d58b5adcf733787 to your computer and use it in GitHub Desktop.
Save David-Hackro/b4d8722cce3297bc1d58b5adcf733787 to your computer and use it in GitHub Desktop.
func almostIncreasingSequence(sequence: [Int]) -> Bool {
if (isIncreasingSequence(sequence : sequence)) {
return true;
}
for (n, c) in sequence.enumerated() {
var tmpSequence = sequence.dropFirst(0);
tmpSequence = tmpSequence[n...1];
if (isIncreasingSequence(sequence : Array<Int>(tmpSequence))) {
return true;
}
}
return false;
}
func isIncreasingSequence(sequence: [Int]) -> Bool {
for (n, c) in sequence.enumerated() {
if (sequence[n] >= sequence[n + 1]) {
return false;
}
}
return true;
}
//almostIncreasingSequence([1, 3, 2, 1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment