Try to verify my code...No Stack..No HashMap..Just Java Code,what is the time complexity?


  • 0
    S
    public class Solution {
        public int getBig(int[] nums,int val){
            int index=0;
            for(int i=0;i<nums.length;i++){
                if(nums[i]==val)
                {
                    index=1;
                }
                if(index==1&&nums[i]>val)
                {
                    return nums[i];
                }
            }
            return -1;
        }
        public int[] nextGreaterElement(int[] findnums, int[] nums) {
            for(int i=0;i<findnums.length;i++){
                int val=getBig(nums,findnums[i]);
                findnums[i]=val;
            }
            return findnums;
        }
    }
    

Log in to reply
 

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