My C++ Code (16ms)

  • 0

    I just used the find function to solve this problem. Because there is no find function when we submit our code, so I just write a find function.

    #code block

    class Solution {
    vector<vector<int>> permute(vector<int>& nums) {
    vector<vector<int>> res;
    vector<int> path;
    return res;

    void find(vector<int>& nums, vector<int>& path, vector<vector<int>>& res, int begin){
        if (nums.size() <= path.size()){res.push_back(path); return;}
        for (int i = begin;i < nums.size(); i++) {
            if (find(path.begin(), path.end(),nums[i]) ==  path.end()) {

    template<class InputIterator, class T>
    InputIterator find (InputIterator first, InputIterator last, const T& val)
    while (first!=last) {
    if (*first==val) return first;
    return last;

Log in to reply

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