原创 258. Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: G

原创 264. Ugly Number II

Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2,

原创 260. Single Number III

Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear ex

原创 283. Move Zeroes

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the

原创 268. Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.

原创 279. Perfect Squares

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum

原创 289. Game of Life

According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised

原创 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

原创 287. Find the Duplicate Number

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at leas

原创 284. Peeking Iterator

Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that s

原创 237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Suppos

原创 242. Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = “anagram”, t =

原创 275. H-Index II

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?

原创 274. H-Index

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute

原创 263. Ugly Number

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime fa