Java solution


  • 0
    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < nums.length; ++i) {
    	for (int j = i + 1; j < nums.length; ++j) {
    		if (nums[i] < nums[j]) {
    			map.put(nums[i], nums[j]);
    			break;
    		}
    	}
    }
    for (int i = 0; i < findNums.length; ++i) {
    	findNums[i] = map.getOrDefault(findNums[i], -1);
    }
    return findNums;
    

Log in to reply
 

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