LeetCode268. Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. For example,Given nums = [0, 1, 3] return...

LeetCode303. Range Sum Query - Immutable

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example:12345Given nums = [-2, 0, 3, -5, 2, -1]sumRange...

LeetCode263. 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...

LeetCode232. Implement Queue using Stacks

Implement the following operations of a queue using stacks. push(x) – Push element x to the back of queue.pop() – Removes the element from in front of queue....

LeetCode237. 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. Supposed the linked list is 1 -> 2 -> 3 -&...

LeetCode231. Power of Two

Given an integer, write a function to determine if it is a power of two. 12345678class Solution {public: bool isPowerOfTwo(int n) { if (n...

LeetCode155. Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) – Push element x onto stack.pop() – Removes the ele...

LeetCode234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 把前一半反转一下,然后用两个指针,将一个移到中间后,开始逐个看两个指针上的数据是否...

LeetCode141. Linked List Cycle

Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 一个笨办法是将每个节点插入一个unordered_map里,每次插入前去查一下是否已经存在,这...

LeetCode136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Co...