C# o(n) time, O(1) space

  • 0

    Thanks @admin. below ans is just C# version of @qgambit2 's one

    public class Solution {
        public bool IncreasingTriplet(int[] nums) {
            int a = int.MaxValue;
            int b = int.MaxValue;
            for (int i = 0; i < nums.Length; i++) {
                if (nums[i] <= a) a = nums[i];
                else if (nums[i] <= b) b = nums[i];
                else return true;            
            return false;

  • 1

    give u an array to test.


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.