Untitled
unknown
plain_text
a year ago
1.5 kB
5
Indexable
import java.util.*; class UserSolution { Map<String, List> map; void init() { map = new HashMap<String, List>(); } void makeList(char mName[], int mLength, int mListValue[]) { List list = new List(); list.origin = Arrays.copyOf(mListValue, mLength); map.put(toStr(mName), list); } void copyList(char mDest[], char mSrc[], boolean mCopy) { List src = map.get(toStr(mSrc)); if (!mCopy) map.put(toStr(mDest), src); else { List list = new List(); list.origin = src.origin; list.updated.putAll(src.updated); list.isCopy = src.isCopy = true; map.put(toStr(mDest), list); } } void updateElement(char mName[], int mIndex, int mValue) { List list = map.get(toStr(mName)); if (list.isCopy) list.updated.put(mIndex, mValue); else list.origin[mIndex] = mValue; } int element(char mName[], int mIndex) { List list = map.get(toStr(mName)); if (list.updated.get(mIndex) != null) return list.updated.get(mIndex); return list.origin[mIndex]; } String toStr(char s[]) { int n = -1; while (s[++n] != 0); return new String(s, 0, n); } } class List { int origin[]; Map<Integer, Integer> updated = new HashMap<>(); boolean isCopy; }
Editor is loading...
Leave a Comment