Add Digits
Given an integer , repeatedly add all its digits until the result has only one digit, and return it.
Example 1:
Given an integer , repeatedly add all its digits until the result has only one digit, and return it.
Example 1:
Given the of a binary tree, return all root-to-leaf paths in any order.
A leaf is a node with no children.
Given two strings and , return if is an anagram of , and otherwise.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Given the of a singly linked list, return if it is a palindrome or otherwise.
Example 1:
232.Implement Queue using Stacks
Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (, , , and ).
Implement the class:
Given an integer , return if it is a power of two. Otherwise, return .
An integer is a power of two, if there exists an integer such that .
You are given a sorted unique integer array .
A range is the set of all integers from to (inclusive).
Given the of a binary tree, invert the tree, and return its root.
Example 1:
225.Implement Stack using Queues
Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (, , , and ).
Implement the class:
Given an integer array and an integer , return if there are two distinct indices and in the array such that and .
Example 1: