Untitled
unknown
plain_text
a year ago
1.3 kB
4
Indexable
import java.util.Map; import java.util.TreeMap; class UserSolution { TreeMap<Integer, Integer> map[]; public void init() { map = new TreeMap[102]; for(int i=0;i<102;i++) { map[i] = new TreeMap<Integer, Integer>(); } } public void add(int mX, int mY) { map[mX].put(mY, mX+1); map[mX+1].put(mY, mX); } public void remove(int mX, int mY) { map[mX].remove(mY); map[mX+1].remove(mY); } public int numberOfCross(int mID) { int cnt =0; int mX = mID; int mY = 0; while (true) { Map.Entry<Integer, Integer> mpEntry = map[mX].higherEntry(mY); if(mpEntry==null) break; mX = mpEntry.getValue(); mY = mpEntry.getKey(); cnt++; } return cnt; } public int participant(int mX, int mY) { while (true) { Map.Entry<Integer, Integer> mpEntry = map[mX].lowerEntry(mY); if(mpEntry==null) break; mX = mpEntry.getValue(); mY = mpEntry.getKey(); } return mX; } }
Editor is loading...
Leave a Comment