class Solution {
public:
Solution(vector<int>& nums) {
}
int pick(int target) {
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(nums);
* int param_1 = obj->pick(target);
*/
class Solution:
def __init__(self, nums: List[int]):
self.nums = nums
def pick(self, target: int) -> int:
res = -1
k = 0
for i in range(0, len(self.nums)):
if self.nums[i] == target:
k += 1
if random.randint(1, k) == 1:
res = i
return res
# Your Solution object will be instantiated and called as such:
# obj = Solution(nums)
# param_1 = obj.pick(target)