er.vishalmehta83
BAN USERMap<Integer, Integer> map = new HashMap<>();
Set<Integer> set = new HashSet<>();
for (int i = 0; i < array.length; i++) {
if (!set.contains(array[i])) {
set.add(array[i]);
if (map.containsKey(array[i])) {
System.out.println("combination at : " + map.get(array[i]) + " and : " + i);
}
map.put(sum - array[i], i);
}
}
boolean validParenthsis(String str) {
Stack<Character> stk = new Stack<>();
for (int i = 0 ; i < str.length ; i++) {
char currChar = str.charAt(i);
if (currChar == '{' || currChar == '[' || currChar == '(' ){
stk.push(currChar);
} else {
if (stk.isEmpty() || stk.pop() != currChar) {
return false;
}
}
}
}
return stk.isEmpty();
}
int d(Node node) {
if (node == null) {
return 0;
}
return 1 + Math.max(d(node.left), d(node.right));
}
- er.vishalmehta83 February 03, 2016