problemscpp
A collection of my answers to algorithm problems in c++.
载入中...
搜索中...
未找到
leetcode::shuffle_an_array::Solution类 参考

#include <leetcode.h>

Public 成员函数

 Solution (vector< int > &nums)
 Initializes the object with the integer array nums.
 
vector< int > reset ()
 Resets the array to its original configuration and returns it.
 
vector< int > shuffle () const
 Returns a random shuffling of the array.
 

Private 属性

vector< int > nums
 

详细描述

在文件 leetcode.h2317 行定义.

构造及析构函数说明

◆ Solution()

leetcode::shuffle_an_array::Solution::Solution ( vector< int > & nums)
explicit

Initializes the object with the integer array nums.

在文件 leetcode.cpp6158 行定义.

6159 : nums(nums) { srand(time(nullptr)); }

引用了 nums.

成员函数说明

◆ reset()

vector< int > leetcode::shuffle_an_array::Solution::reset ( )

Resets the array to its original configuration and returns it.

在文件 leetcode.cpp6145 行定义.

6145{ return nums; }

引用了 nums.

◆ shuffle()

vector< int > leetcode::shuffle_an_array::Solution::shuffle ( ) const
nodiscard

Returns a random shuffling of the array.

在文件 leetcode.cpp6147 行定义.

6147 {
6148 vector<int> ans;
6149 vector<int> cpy = nums;
6150 while(!cpy.empty()) {
6151 const int idx = rand() % cpy.size();
6152 ans.emplace_back(cpy[idx]);
6153 cpy.erase(cpy.begin() + idx);
6154 }
6155 return ans;
6156 }
vector< vector< int > > ans

引用了 nums.

类成员变量说明

◆ nums

vector<int> leetcode::shuffle_an_array::Solution::nums
private

在文件 leetcode.h2318 行定义.

被这些函数引用 Solution(), reset() , 以及 shuffle().


该类的文档由以下文件生成: