国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

LeetCode 46. Permutations

2019-11-08 02:46:23
字體:
供稿:網(wǎng)友

Given a collection of distinct numbers, return all possible permutations.

For example,[1,2,3] have the following permutations:

[  [1,2,3],  [1,3,2],  [2,1,3],  [2,3,1],  [3,1,2],  [3,2,1]]answer:

class Solution {public:    vector<vector<int>> permute(vector<int>& nums) {        int length = nums.size();        vector<vector<int>> result1,result2;        vector<int> temp;        result1.push_back(temp);        bool flag = false;        for(int i = 0; i < length; i ++){            for(int k = 0;k < length; k ++){                for(int j = 0; j < result1.size(); j ++){                    flag = false;                    temp = result1[j];                    for(int l = 0; l < temp.size(); l ++){                        if(temp[l] == nums[k]){                            flag = true;                            break;                        }                    }                    if(flag) continue;                    temp.push_back(nums[k]);                    result2.push_back(temp);                    temp.pop_back();                }            }            result1 = result2;            result2.clear();        }        return result1;    }    };


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 高尔夫| 仁怀市| 安康市| 崇义县| 新郑市| 襄城县| 巴林左旗| 河东区| 桂东县| 兴文县| 舒城县| 堆龙德庆县| 杭锦旗| 疏勒县| 体育| 盐池县| 漾濞| 墨竹工卡县| 读书| 柳州市| 中阳县| 黄骅市| 南澳县| 靖远县| 遵义县| 贵德县| 历史| 四平市| 建湖县| 七台河市| 东山县| 青州市| 临猗县| 西乌| 长子县| 珠海市| 大英县| 博客| 准格尔旗| 大丰市| 新绛县|