[Leetcode] Count Primes 数素数

2015-09-05
阅读 1 分钟
13.4k
Description: Count the number of prime numbers less than a non-negative number, n.

[Leetcode] Reverse Linked List 反转链表

2015-09-05
阅读 3 分钟
8.6k
Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?

[Leetcode] Palindrome Linked List 回文链表

2015-09-05
阅读 2 分钟
5.7k
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?

[Leetcode] Merge Sorted Array 合并数组

2015-09-05
阅读 1 分钟
5.3k
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectiv...

[Leetcode] Climbing Stairs 爬楼梯

2015-09-05
阅读 1 分钟
5.9k
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?

[Leetcode] Add Binary 二进制相加

2015-09-05
阅读 1 分钟
7.2k
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".

[Leetcode] Minimum Window Substring 最小字符串窗口

2015-09-05
阅读 2 分钟
7.4k
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BANC". Note: If there is no such window in S that covers all characters in T, return the emtpy string "". If t...

[Leetcode] Implement strStr() 实现StrStr

2015-09-05
阅读 2 分钟
9.4k
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

[Leetcode] Rectangle Area 矩形面积

2015-09-04
阅读 1 分钟
5.8k
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Rectangle Area Assume that the total area is never beyond the maximum possible value of int.

[Leetcode] Rotate Array 旋转数组

2015-09-04
阅读 1 分钟
9k
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].

[Leetcode] Kth Largest Element in an Array 数组中第K大元素

2015-09-04
阅读 3 分钟
17.6k
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5. Note: You may assume k is always valid, 1 ≤ k ≤ array's length.

[Leetcode] Kth Smallest Element in a BST 二叉搜索树第k小节点

2015-09-04
阅读 2 分钟
7.1k
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements. Follow up: What if the BST is modified (insert/delete operations) often and you need to find the kth smallest frequently? How woul...

[Leetcode] Restore IP Address 修复IP地址

2015-09-04
阅读 2 分钟
4.4k
Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)

[Leetcode] Single Number 单身数

2015-09-03
阅读 3 分钟
4.2k
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. Could you implement it without using extra memory?

[Leetcode] Word Break 单词分解

2015-09-02
阅读 4 分钟
10.5k
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcode", dict = ["leet", "code"]. Return true because "leetcode" can be segmented as "leet code".

[Leetcode] Word Ladder 单词爬梯

2015-09-02
阅读 2 分钟
6k
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformation sequence from beginWord to endWord,such that: Only one letter can be changed at a time Each intermediate word must exist in the dictionary For example, Given: start = "hit" end = "cog" dict = ["h...

[Leetcode] Sqrt 开方

2015-09-02
阅读 1 分钟
4.2k
我们知道必定存在这么两个整数a和b,a^2 <= sqrt(x) <= b^2,所以我们要做的其实就是缩小这个ab的范围。使用二分法解这题时,通过比较mid^2和x大小来确定我们在哪一个半片中搜索。

[Leetcode] Word Search 单词搜索

2015-09-02
阅读 5 分钟
6.5k
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. For example, Given board = {代码....

[Leetcode] Copy List with Random Pointer 复制随机指针

2015-09-01
阅读 2 分钟
3.6k
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.

[Leetcode] Binary Tree Maximum Path Sum 二叉树最大路径和

2015-08-30
阅读 1 分钟
10.5k
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, {代码...} Return 6.

[Leetcode] Path Sum I & II & III 路径和1,2,3

2015-08-30
阅读 7 分钟
3.9k
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, {代码...} return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.

[Leetcode] Binary Tree Traversal 二叉树遍历

2015-08-29
阅读 7 分钟
11.1k
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, {代码...} return [1,2,3].

[Leetcode] Binary Tree Right Side View 二叉树右视图

2015-08-29
阅读 2 分钟
7.7k
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the following binary tree, {代码...} You should return [1, 3, 4].

[Leetcode] Lowest Common Ancestor of a Binary Tree 最小公共祖先

2015-08-29
阅读 3 分钟
20.1k
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a n...

[Leetcode] Balanced Binary Tree 平衡二叉树

2015-08-29
阅读 1 分钟
5.1k
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

[Leetcode] Triangle 三角形

2015-08-27
阅读 1 分钟
2.7k
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle {代码...} The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).

[Leetcode] Unique Paths 唯一路径

2015-08-27
阅读 3 分钟
5.4k
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). How many possible unique pat...

[Leetcode] Subset 子集

2015-08-27
阅读 3 分钟
5k
Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets.

[Leetcode] Delete Node/Remove Element in a Linked List 删除链表节点

2015-08-27
阅读 1 分钟
4.3k
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 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.

[Leetcode] Largest Rectangle (in Histogram) 最大矩形

2015-08-27
阅读 4 分钟
5.6k
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has...