Articles
-
142 - Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
-
141 - Linked List Cycle
Given a linked list, determine if it has a cycle in it.
-
19 - Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.
-
Two Lists Sum
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.</p>
-
86 - Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions.
-
Remove Duplicates from Unsorted List
Write a removeDuplicates() function which takes a list and deletes any duplicate nodes from the list. The list is not sorted.
-
82 - Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
-
83 - Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.
-
66 - Plus One
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list.
-
263 - Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is typically treated as an ugly number.
-
Majority Number III
Given an array of integers and a number k, the majority number is the number that occurs more than 1/k of the size of the array.
-
229 - Majority Element II
Given an integer array of size n, find all elements that appear more than n/3 times. The algorithm should run in linear time and in O(1) space.
-
169 - Majority Number
Given an array of size n, find the majority element. The majority element is the element that appears more than {n/2} times
-
Print Numbers by Recursion
Print numbers from 1 to the largest number with N digits by recursion.
-
1 - A + B Problem
Write a function that add two numbers A and B. You should not use + or any arithmetic operators.
-
Fibonacci
Find the Nth number in Fibonacci sequence. A Fibonacci sequence is defined as follow: The first two numbers are 0 and 1. The ith number is the sum of i-1th number and i-2 th number.
-
365 - Count 1 in Binary
Count how many 1 in binary representation of a 32-bit integer.
-
Hash Function
In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal to zero. The objective of designing a hash function is to "hash" the key as unreasonable as possible. A good hash function can avoid collision as less as possible. A widely used hash function algorithm is using a magic number 33, consider any string as a 33 based big integer like follow:
-
Fast Power
Calculate the an a^n % b where a, b and n are all 32bit integers.
-
179 - Update Bits
Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (eg , M becomes a substring of N located at i and starting at j)
-
96 - Unique Binary Search Trees
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?
-
172 - Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity.
-
231 - Power of Two
Given an integer, write a function to determine if it is a power of two.
-
260 - Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
-
137 - Single Number II
Given 3n + 1 numbers, every numbers occurs triple times except one, find it.
-
136 - Single Number
Given an array of integers, every element appears twice except for one. Find that single one.
-
Wood Cut
Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the same length. What is the longest length you can get from the n pieces of wood? Given L k, return the maximum length of the small pieces.
-
69 - Sqrt(x)
Compute and return the square root of x.
-
4 - Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
-
240 - Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
- Integers in each row are sorted in ascending from left to right.
- Integers in each column are sorted in ascending from top to bottom.