Why is the data so weak?


  • 0
    N

    there are many programs which i search on the Internet can get the accept on this problem , but most of them can't through my test data. for example, [4 5 3 1 2 6]
    the test data is so weak.


  • 0

    [4 5 3 1 2 6] is not a valid input. Could you please paste the code of some programs you think are wrong but got accepted, with its accompanying test case?


  • 0
    N

    the accept code:
    class Solution {
    public:
    int findMin(vector<int> &num) {
    return assistFindMin(num, 0, num.size() - 1);
    }

    private:
    int assistFindMin(vector<int> &num, int begin, int end) {
    if(begin == end || num[begin] < num[end])
    return num[begin];
    int mid = (begin + end) >> 1;
    if(num[mid] > num[begin])
    return assistFindMin(num, mid + 1, end);
    else if(num[mid] < num[begin])
    return assistFindMin(num, begin + 1, mid);
    else {
    if(num[mid] > num[end])
    return assistFindMin(num, mid + 1, end);
    else
    return min(assistFindMin(num, begin, mid), assistFindMin(num, mid + 1, end));
    }
    }

        int min(int a, int b) {  
            return a <= b ? a : b;  
        }  
    

    };

    another question is :
    why is the test data invalid?
    1 2 3 4 5 6 -> 4 5 3 1 2 6 the pivot is 3.It's invalid??


  • 0

    For the array [1 2 3 4 5 6] there are 6 possible rotation configurations:

    • [1 2 3 4 5 6]
    • [6 1 2 3 4 5]
    • [5 6 1 2 3 4]
    • [4 5 6 1 2 3]
    • [3 4 5 6 1 2]
    • [2 3 4 5 6 1]

    I don't see [4 5 3 1 2 6] belong to any of the above rotation configurations.


  • 0
    N

    sorry,I was wrong.Thank you for your solution.


Log in to reply
 

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