Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int suurin(int k, int[] luvut) {
- TreeSet<Integer> ts = new TreeSet();
- for(int i = 0; i < luvut.length; i++) {
- if(ts.size() == k && ts.first()<=luvut[i]) {
- ts.pollFirst();
- ts.add(luvut[i]);
- } else if(ts.size() < k) {
- ts.add(luvut[i]);
- }
- }
- return ts.first();
- }
Add Comment
Please, Sign In to add comment