What the time complexity of this solution?


  • 0
    G

    public class Solution {

    int[] nums = null;
    
    public Solution(int[] nums) {
        this.nums = nums;
    }
    
    public int pick(int target) {
        Random rand = new Random();
        while(true){
            int index = rand.nextInt(nums.length);
            if(nums[index] == target){
                return index;
            }
        }
    }
    

    }


Log in to reply
 

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