Climbing Stairs

Title: Climbing Stairs Source: leetcode.com You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Java solution Java /* https://leetcode.com/problems/climbing-stairs/ */ import java.util.HashSet; class ClimbStairs { HashSet set = ...

Binary Tree Paths

Title: Binary Tree Paths Source: leetcode.com Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 12345    1 /   \2     3 \  5 All root-to-leaf paths are: ["1->2->5", "1->3"] 1 ["1->2->5", "1->3"] Java solution Java /* https://leetcode.com/problems/binary-tree-paths/ */ import java.util.List; import java.util.ArrayList; public ...

Add Digits

Title: Add Digits Source: leetcode.com Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do ...

Bulls and Cows

Title: Bulls and Cows Source: leetcode.com You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret ...