Cosmoteer Modding Documentation

Popular Posts

Friday, 27 January 2023

Find Last Digit In Array




1. sort array, this sorts numbers by least to most

2. find last digit by iterating through the array and doing -1 

3. print out the result

import java.util.Arrays;

class Solution {
    public int majorityElement(int[] nums) {
        Arrays.sort(nums);
        int size = nums[nums.length -1];
        System.out.print(size);

    return size;
    }
   
   
}

No comments:

Post a Comment