Quick actions

cmd+k|ctrl+k

Navigation

Languages

LonelyInteger

Snippet info

Language

Java

Visibility

public

Author

yudhistiraaaa20

Created

2024-12-31T09:46:22.663432Z

Updated

2024-12-31T09:46:22.663432Z

import java.util.*;

class Main {
    public static void main(String[] args) {
        List<Integer> a = new ArrayList<>(Arrays.asList(1,2,3,4,3,2,1));
        int length = a.size();
        HashMap<Integer, Integer> lonely = new HashMap<>();
        for (int i = 0; i < length; i++) {
        int count = 0;
            for (int j = 0; j < length; j++) {
                if(a.get(i) == a.get(j)){
                    count++;
                    lonely.put(a.get(i), count);
                }
            }
        }
        System.out.println(lonely);
    }
}
INFO