bruce force java with o(n) time o(1) space


  • 0
    C

    public class Solution {
    int[]nums;
    public Solution(int[] nums) {
    this.nums = nums;
    }

    public int pick(int target) {
        int test = (int)(Math.random()*nums.length);
        while(nums[test]!=target){
            test = (int)(Math.random()*nums.length);
        }
        return test;
    }
    

    }


Log in to reply
 

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