My c++ solution with question what's the difference between numeric_limits and 2147XXX

  • 0
    bool increasingTriplet(vector<int>& nums) {
    if (nums.size() < 1) return false;
    int min = nums[0];
    **int mid = std::numeric_limits<int>::max();**
    for (size_t i = 0; i<nums.size(); ++i)
    	if (nums[i] > mid) return true;
    	if (nums[i] > min)
    		mid = nums[i];// find first element greater than min;
    		min = nums[i];
    return false;


    if I use "mid = std::numeric_limits<int>::max(); "
    It will fail at case [2,4,-2,-3].
    but mid = 2147483647 will pass.

    could you tell me why? thx:)

  • 0

    No difference, both versions compute the same for that case and both versions get accepted.

  • 0

    Thank you, I finally find out where the WA comes from. < vs <= problems..

Log in to reply

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