leetcode
文章平均质量分 83
leetcode各个题目的思路解法和大神解法的介绍
huanghanqian
少年,你还很菜。
展开
-
leetcode 85. Maximal Rectangle(最大全1子矩阵)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0原创 2017-12-11 13:07:45 · 1818 阅读 · 0 评论 -
leetcode 234. 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?意思是判断长度为 n 的单向链表是否为回文结构。这道题的思路就是:1. 获取链表的中点,使用龟兔算法的方法,两个指针,一个遍历速度是另外一个的两倍,找到原创 2017-12-18 19:37:13 · 273 阅读 · 0 评论 -
leetcode 91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2017-12-30 21:35:33 · 230 阅读 · 0 评论 -
leetcode 124. Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The pa原创 2018-01-01 22:59:01 · 179 阅读 · 0 评论 -
Weekly Contest 70 leetcode 779. K-th Symbol in Grammar
On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.Given row N and index K, r原创 2018-02-04 18:40:36 · 751 阅读 · 0 评论 -
Weekly Contest 70 leetcode 777. Swap Adjacent in LR String
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Giv原创 2018-02-04 22:36:58 · 406 阅读 · 0 评论 -
Weekly Contest 70 leetcode 778. Swim in Rising Water
On an N x N grid, each square grid[i][j] represents the elevation(高度) at that point (i,j).Now rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to anot...原创 2018-02-09 23:16:38 · 507 阅读 · 0 评论 -
leetcode 54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You原创 2018-02-10 23:31:46 · 167 阅读 · 0 评论 -
Weekly Contest 71 leetcode 783. Minimum Distance Between BST Nodes
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree.Example :Input: root = [4,2,6,1,3,null,null]O原创 2018-02-11 14:11:36 · 336 阅读 · 0 评论 -
Weekly Contest 71 leetcode 781. Rabbits in Forest
In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them(告诉你 有多少只其他兔子跟它颜色一样). Those answers are placed in an原创 2018-02-11 14:46:24 · 825 阅读 · 0 评论 -
Weekly Contest 71 leetcode 780. Reaching Points
A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence o原创 2018-02-11 15:12:46 · 1060 阅读 · 0 评论 -
Weekly Contest 71 leetcode 782. Transform to Chessboard
An N x N board contains only 0s and 1s. In each move, you can swap any 2 rows with each other, or any 2 columns with each other.What is the minimum number of moves to transform the board into原创 2018-02-11 15:46:56 · 1117 阅读 · 0 评论 -
Weekly Contest 72 leetcode 784. Letter Case Permutation
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.Examples:Input: S = "a1b2"原创 2018-02-18 13:45:27 · 516 阅读 · 0 评论 -
Weekly Contest 72 leetcode 785. Is Graph Bipartite?
Given a graph, return true if and only if it is bipartite.Recall that a graph is bipartite if we can split it's set of nodes into two independent subsets A and B such that every edge in the grap原创 2018-02-18 14:22:35 · 844 阅读 · 0 评论 -
Weekly Contest 72 leetcode 787. Cheapest Flights Within K Stops
There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w.Now given all the cities and fights, together with starting city src and the destinatio原创 2018-02-18 16:58:06 · 841 阅读 · 0 评论 -
Weekly Contest 72 leetcode 786. K-th Smallest Prime Fraction
A sorted list A contains 1, plus some number of primes. Then, for every p < q in the list, we consider the fraction p/q.What is the K-th smallest fraction considered? Return your answer as an原创 2018-02-18 20:09:27 · 784 阅读 · 0 评论 -
一篇文章搞懂leetcode位操作算法题
本文将根据题目总结常用的位操作常用的解决算法问题的技巧Single Number落单的数给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。思路:一个数字和自己进行异或操作会是0,由于异或操作满足交换定律,一个数和0进行异或操作还是本身。所以这道题目的思路就来了,将所有出现两次的数异或就都变成了0,最后剩的那个数和0异或就还是本转载 2018-02-21 19:27:00 · 1255 阅读 · 0 评论 -
Weekly Contest 73 leetcode 788. Rotated Digits
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. A number is valid if each digit remains a digit after rotation. 0, 1, and 8原创 2018-02-25 13:36:09 · 1006 阅读 · 1 评论 -
Weekly Contest 73 leetcode 789. Escape The Ghosts
You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is (target[0], target[1]). There are several ghosts on the map, the i-th ghost starts at (ghosts[i][0]原创 2018-02-25 14:17:07 · 370 阅读 · 0 评论 -
Weekly Contest 73 leetcode 791. Custom Sort String
S and T are strings composed of lowercase letters. In S, no letter occurs more than once.S was sorted in some custom order previously. We want to permute the characters of T so that they match原创 2018-02-25 14:57:04 · 560 阅读 · 0 评论 -
Weekly Contest 73 leetcode 790. Domino and Tromino Tiling
We have two types of tiles(地砖): a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated.XX <- dominoXX <- "L" trominoXGiven N, how many ways are there to tile a 2 x N boa原创 2018-02-25 16:37:05 · 573 阅读 · 0 评论 -
leetcode 97. Interleaving String(交叉的字符串)
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret原创 2018-03-11 20:30:37 · 463 阅读 · 0 评论 -
leetcode 29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题目描述得很简单,看上去也很简单,但是呢。。。你不要想得太简单。来看看几个测试用例吧。然后呢,如果你的思路是,一直减被除数,直到被除数小于除数为止,那么也不原创 2018-03-17 18:59:49 · 197 阅读 · 0 评论 -
leetcode 514. Freedom Trail
In the video game Fallout 4(辐射4), the quest(追寻,探索) "Road to Freedom" requires players to reach a metal dial(表盘,拨号盘) called the "Freedom Trail Ring", and use the dial to spell a specific keyword in ord原创 2017-08-27 14:03:26 · 792 阅读 · 0 评论 -
leetcode 367. Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Return原创 2017-08-27 15:12:26 · 277 阅读 · 0 评论 -
leetcode 459. Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli原创 2017-08-27 17:11:03 · 588 阅读 · 0 评论 -
leetcode 488. Zuma Game(祖玛游戏)
Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.Each time, you may choose a ball i原创 2017-08-28 15:55:41 · 2030 阅读 · 1 评论 -
leetcode 501. Find Mode in Binary Search Tree
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node c原创 2017-08-28 17:25:39 · 339 阅读 · 0 评论 -
leetcode 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2017-08-29 13:37:13 · 273 阅读 · 0 评论 -
leetcode 313. Super Ugly Number
Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13,原创 2017-08-29 17:33:59 · 275 阅读 · 0 评论 -
leetcode 110. Balanced Binary Tree
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 diffe原创 2017-08-30 13:44:46 · 328 阅读 · 0 评论 -
leetcode 162. Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in原创 2017-08-30 14:27:05 · 266 阅读 · 0 评论 -
leetcode 407. Trapping Rain Water II
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining.原创 2017-08-30 17:04:22 · 531 阅读 · 0 评论 -
leetcode 154. Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose an array sorted in ascending order is rotated原创 2017-09-02 10:45:30 · 283 阅读 · 0 评论 -
leetcode 654. Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left subtree is the maximum tree constructed f原创 2017-09-02 19:32:33 · 1338 阅读 · 0 评论 -
leetcode 657. Judge Route Circle
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.The move sequence is represented by原创 2017-09-02 20:18:37 · 436 阅读 · 0 评论 -
leetcode 655. Print Binary Tree
Print a binary tree in an m*n 2D string array following these rules:The row number m should be equal to the height of the given binary tree.The column number n should always be an odd number.The r原创 2017-09-03 14:41:21 · 1369 阅读 · 0 评论 -
leetcode 667. Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3,原创 2017-09-03 16:00:57 · 308 阅读 · 0 评论 -
leetcode 653. Two Sum IV - Input is a BST
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input: 5 / \ 3 6 / \原创 2017-09-04 14:29:59 · 1956 阅读 · 0 评论 -
leetcode 661. Image Smoother
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down 四舍五入取靠近零值的舍入数字 ) of原创 2017-09-04 15:43:19 · 1102 阅读 · 0 评论