public int SumOfPrefix(string prefix) { Dictionary <char, MapSumNode> currChildren = Children; int result = 0; for (int i = 0; i < prefix.Length; i++) { if (!currChildren.ContainsKey(prefix[i])) { return(0); } MapSumNode currNode = currChildren[prefix[i]]; result = currNode.currSum; currChildren = currNode.Children; } return(result); }
public void Insert(string s, int value) { Dictionary <char, MapSumNode> currChildren = Children; for (int i = 0; i < s.Length; i++) { MapSumNode temp; if (currChildren.ContainsKey(s[i])) { temp = currChildren[s[i]]; } else { temp = new MapSumNode(s[i]); currChildren.Add(s[i], temp); } temp.currSum += value; currChildren = temp.Children; } }
/** Initialize your data structure here. */ public MapSum() { root = new MapSumNode(); latestValue = new Dictionary <string, int>(); }