My 2-line stl soluthin


  • -5
    S
    class Solution {
    public:
        bool search(vector<int>& nums, int target) {
            sort(nums.begin(), nums.end());
            return binary_search(nums.begin(), nums.end(), target);
        }
    };

  • 0
    A

    you even can just go through whole arrary to get it in O(n).. not even need to sort in O(nlgn) in the first place.


Log in to reply
 

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