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


  • 0
    H

    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
    A

    give u an array to test.

    [1,2,3,1,2,1]
    

Log in to reply
 

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