# Leetcode Algos

```public int climbStairs(int n) {
int[] previousClimbs = new int[n + 1];
previousClimbs[0] = 1;
previousClimbs[1] = 1;
for(int i = 2; i <= n; i++) {
previousClimbs[i] = previousClimbs[i -1] + previousClimbs[i - 2];
}

return previousClimbs[n];
}```
```public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
if (t1 == null)
return t2;
Stack < TreeNode[] > stack = new Stack < > ();
stack.push(new TreeNode[] {t1, t2});
while (!stack.isEmpty()) {
TreeNode[] t = stack.pop();
if (t[0] == null || t[1] == null) {
continue;
}
t[0].val += t[1].val;
if (t[0].left == null) {
t[0].left = t[1].left;
} else {
stack.push(new TreeNode[] {t[0].left, t[1].left});
}
if (t[0].right == null) {
t[0].right = t[1].right;
} else {
stack.push(new TreeNode[] {t[0].right, t[1].right});
}
}
return t1;
}```
```public int[] topKFrequent(int[] nums, int k) {
ArrayList<LinkedList<Integer>> freqList = new ArrayList<>();
for (int i = 0; i <= nums.length; i++) {
}

HashMap<Integer, Integer> elementFreq = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
if (elementFreq.containsKey(nums[i])){
elementFreq.put(nums[i], elementFreq.get(nums[i]) + 1);
}
else {
elementFreq.put(nums[i], 1);
}
}

Iterator<Integer> elemItr = elementFreq.keySet().iterator();
while (elemItr.hasNext()) {
int currKey = elemItr.next();
}

ArrayList<Integer> intsByFreq = new ArrayList<>();
for (int i = 0; i < freqList.size(); i++) {
LinkedList<Integer> currList = freqList.get(i);
ListIterator<Integer> currListItr = currList.listIterator(0);
while (currListItr.hasNext()) {
}
}

int[] topK = new int[k];
int topKIdx = 0;
for (int i = intsByFreq.size() - 1; i >= intsByFreq.size() - k; i--) {
topK[topKIdx] = intsByFreq.get(i);
topKIdx++;
}