Leetcode

Best Time to Buy and Sell Stock

Question Solution Summary LeetCode 121 Question Say you have an array for which the ith element is the price of a given stock on day i.

Climbing Stairs

LeetCode 70 Question 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?

Contains Duplicate

Question Solution First try Improve Summary LeetCode 217 Question Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

Power of Three

Question Solution Summary LeetCode Question Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27 Output: true Example 2:

Count primes

LeetCode 204 Question Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.

Valid Parentheses

LeetCode 20 Question Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ’]’, determine if the input string is valid. An input string is valid if:

Count and Say

LeetCode 38 Question The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "one 1" or 11.

Merge Two Sorted Lists

LeetCode Question Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.

Linked List Cycle

LeetCode 141 Question Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to.

Roman to Integer

LeetCode 13 Question Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one’s added together.