My concise short solution


  • 2
    S
    public int[] nextGreaterElement(int[] findNums, int[] nums) {
    	int n1 = findNums.length, n2 = nums.length;
    	List<Integer> list = new ArrayList<>();
    	for (int i : nums) list.add(i);
    	int[] res = new int[n1];
    	for (int i = 0; i < n1; i++) {
    		int cur = findNums[i];
    		res[i] = -1;
    		for (int k = list.indexOf(cur); k < n2; k++) {
    			if (nums[k] > cur){
    				res[i] = nums[k];
    				break;
    			}
    		}
    	}
    	return res;
    }
    

Log in to reply
 

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