Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static long[] planting(Event[] events) {
- TreeSet<Long> erdo = new TreeSet<>();
- for(int i = 0; i < events.length; i++) {
- if(events[i].action.equals("kihajt")) {
- if((erdo.ceiling(events[i].position) == null) && (erdo.floor(events[i].position) == null)) {
- erdo.add(events[i].position);
- }
- else if(erdo.ceiling(events[i].position) == null) {
- if(Math.abs(events[i].position - erdo.floor(events[i].position)) >= 250) {
- erdo.add(events[i].position);
- }
- } else if(erdo.floor(events[i].position) == null) {
- if(Math.abs(erdo.ceiling(events[i].position) - events[i].position) >= 250){
- erdo.add(events[i].position);
- }
- } else if (Math.abs(erdo.ceiling(events[i].position) - events[i].position) >= 250 &&
- Math.abs(events[i].position - erdo.floor(events[i].position)) >= 250) {
- erdo.add(events[i].position);
- }
- } else {
- erdo.remove(events[i].position);
- }
- }
- long[] eredmeny = new long[erdo.size()];
- int i = 0;
- for(Long elem: erdo) {
- eredmeny[i] = elem;
- i++;
- }
- return eredmeny;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement