Home  >  Article  >  Java  >  How to solve Java array, character and arithmetic sequence problems

How to solve Java array, character and arithmetic sequence problems

WBOY
WBOYforward
2023-05-04 17:40:071175browse

Question 1

How to solve Java array, character and arithmetic sequence problems

Solution

class Solution {
    public int[] relativeSortArray(int[] arr1, int[] arr2) {
        int[] arr = new int[1001];
        int[] ans = new int[arr1.length];
        int index = 0;
        for(int i =0;i0){
                arr[arr2[i]]--;
                ans[index] = arr2[i];
                index++;
            }
        }
        for(int i =0;i

Question 2

How to solve Java array, character and arithmetic sequence problems

Solution

class Solution {
    public int findLucky(int[] arr) {
        int[] nums = new int[500];
        for(int i =0;i

Question 3

How to solve Java array, character and arithmetic sequence problems

Solution

class Solution {
    public int maxPower(String s) {
        if(s.length()==1) return 1;
        int left = 1;
        int max = Integer.MIN_VALUE;
        int con = 1;
        while(left

Question 4

How to solve Java array, character and arithmetic sequence problems

Solution

class Solution {
    public boolean canMakeArithmeticProgression(int[] arr) {
        Arrays.sort(arr);
        int num = arr[1]-arr[0];
        
        for(int i = 1;i

The above is the detailed content of How to solve Java array, character and arithmetic sequence problems. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete