map.get(ch) is an Integer, and omap.get(ch) is also an Integer. The == for two objects does not compare the value they contain. it checks whether the two objects are same. You could try:
map.get(ch).intValue() == omap.get(ch).intValue()
Hope it helps
yzhao
@yzhao
Posts made by yzhao

RE: Get Wrong with the large test case. Can anyone me where I am wrong

Is there a better solution?
I made a function to generate all the subsets of a length of k. Then I called this function n times with the k increased from 1 to n (n is the length of the array S). Is there a better solution? It seems we could make some uses of the generated subsets. For example, when we have all the subsets of k=1, could we use them to generate the subsets of k=2? Thanks.

RE: Timeout ?? using 2 queues but O(N) only..... Need urgent help....Thanks..
I used one queue. Just keep adding TreeNodes to the same queue. To tell different levels, I used a dummy node: every time we see the dummy node, we know it is the end of the level. Then, we insert another dummy node to the queue to mark the end of the next level. I think a counter will also work ok.
Following is my code: (I hope it helps)public ArrayList<ArrayList<Integer>> levelOrder(TreeNode root) { Queue<TreeNode> q = new LinkedList<TreeNode>(); TreeNode dummy = new TreeNode(1); ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); if (root == null) return result; ArrayList<Integer> tmpal = new ArrayList<Integer>(); q.add(root); q.add(dummy); while (!q.isEmpty()) { TreeNode tmp = q.poll(); if (tmp == dummy) { q.add(dummy); if (tmpal.isEmpty()) break; //to avoid infinite loop result.add(tmpal); tmpal = new ArrayList<Integer>(); } else { if (tmp.left != null) q.add(tmp.left); if (tmp.right != null) q.add(tmp.right); tmpal.add(tmp.val); } } return result; }

RE: A very nice solution (from Ants Aasma @stackoverflow)
I did a small change (thanks for the down vote...):
public class Solution { public int firstMissingPositive(int[] A) { // added line9 condition to avoid infinite loop // added line13, the i, to check the swapped item. Or we failed to check all the numbers. // ref http://stackoverflow.com/questions/1586858/findthesmallestintegernotinalist if (A.length == 0) return 1; for (int i = 0; i < A.length; i++) { if (A[i] <= A.length && A[i] > 0 && A[i] != i+1) { if (A[A[i]1] != A[i]) { //line 9 int tmp = A[A[i]1]; A[A[i]1] = A[i]; A[i] = tmp; i; //line 13 } } } for (int i = 0; i < A.length; i++) { if (A[i] != i+1) return i+1; } return A.length+1; } }

A very nice solution (from Ants Aasma @stackoverflow)
time complexity is O(N) and space complexity is O(1).
Link: http://stackoverflow.com/questions/1586858/findthesmallestintegernotinalist
Posted by Ants Aasma on Oct 20 '09.The code is pasted here:
#Pass 1, move every value to the position of its value for cursor in range(N): target = array[cursor] while target < N and target != array[target]: new_target = array[target] array[target] = target target = new_target #Pass 2, find first location where the index doesn't match the value for cursor in range(N): if array[cursor] != cursor: return cursor return N