timpham2003
BAN USERCan be as simple as 1 single function like this
static List<String> permute(int[] arr, int sum) {
if(sum <=0)
return Collections.emptyList();
ArrayList<String> result = new ArrayList<String>();
for(int i : arr) {
if(i == sum) {
result.add(String.valueOf(i));
return result;
}
}
for(int i : arr) {
for(String s : permute(arr, sum - i)) {
result.add(i + s);
}
}
return result;
}
static LLNode reversePair(LLNode head) {
if(head == null || head.next == null)
return head;
LLNode next1 = head.next;
LLNode next2 = next1.next;
next1.next = head;
head.next = reversePair(next2);
return next1;
}
int countNode(root) {
if(root == null)
return 0;
int cnt = 0;
if(root.left != null && root.value > root.left.value)
cnt += 1 + countNodes(root.left);
if(root.right != null && root.value > root.right.value)
cnt += 1 + countNodes(root.right);
return cnt;
This question is pretty straightforward. Result is -4720. You need to maintain a symbol lookup table (x = 5, y = 4970, etc.)
}
- timpham2003 September 10, 2017