Untitled
unknown
plain_text
a year ago
2.5 kB
15
Indexable
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
class UserSolution {
String char2String(char[] mName) {
String s = "";
for (int i = 0; mName[i] != '\0'; i++) {
s += mName[i];
}
return s;
}
class Node {
int idxList;
int index;
int value;
Node head;
String root;
String copyOf;
HashMap<Integer, Integer> values;
List<String> childs;
Node() {
values = new HashMap<Integer, Integer>();
childs = new ArrayList<String>();
}
Node(int idxList, int index, int value) {
this.idxList = idxList;
this.index = index;
this.value = value;
}
}
HashMap<String, Node> map;
int[][] origin;
int idxList;
public void init() {
origin = new int[10][200000];
map = new HashMap<String, UserSolution.Node>();
idxList = 0;
}
public void makeList(char mName[], int mLength, int mListValue[]) {
String name = char2String(mName);
Node nNode = new Node(idxList, -1, -1);
for (int i = 0; i < mLength; i++) {
origin[idxList][i] = mListValue[i];
}
map.put(name, nNode);
idxList++;
}
public void copyList(char mDest[], char mSrc[], boolean mCopy) {
String nameDes = char2String(mDest);
String nameSrc = char2String(mSrc);
Node node = map.get(nameSrc);
if (mCopy) {
Node newNode = new Node(node.idxList, -1, -1);
newNode.head = node.head;
map.put(nameDes, newNode);
return;
}
map.put(nameDes, node);
return;
}
public void updateElement(char mName[], int mIndex, int mValue) {
String name = char2String(mName);
Node node = map.get(name);
Node nNode = new Node(node.idxList, mIndex, mValue);
nNode.head = node.head;
node.head = nNode;
}
public int element(char mName[], int mIndex) {
String name = char2String(mName);
Node node = map.get(name);
Node current = node;
while (node != null) {
if (node.index == mIndex)
return node.value;
node = node.head;
}
return origin[current.idxList][mIndex];
}
}Editor is loading...
Leave a Comment