LeetCode
会编程的靓仔
这个作者很懒,什么都没留下…
展开
-
338. Counting Bits 难度:中等
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you sh原创 2017-09-23 21:50:33 · 196 阅读 · 0 评论 -
406. Queue Reconstruction by Height Difficulty : Medium
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this p原创 2017-10-10 21:18:14 · 176 阅读 · 0 评论 -
513. Find Bottom Left Tree Value Difficulty : mediate
Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3 / / \ 4 5 6原创 2017-10-04 23:06:39 · 212 阅读 · 0 评论 -
540. Single Element in a Sorted Array Difficulty:Medium
Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element that appears only once.Example 1:Input: [1,1,2,3,3原创 2017-10-11 20:33:46 · 294 阅读 · 0 评论 -
526. Beautiful Arrangement Difficulty: Medium
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 <= i <原创 2017-10-28 21:13:22 · 221 阅读 · 0 评论 -
695. Max Area of Island Difficulty: Easy
Given a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surroun原创 2017-10-28 21:28:22 · 249 阅读 · 0 评论 -
Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.算法解析:既可以用深度优先搜索,也可以用广度优先搜索,前者可以节省代码,后者可以提高速原创 2017-10-28 22:10:01 · 282 阅读 · 0 评论 -
647. Palindromic Substrings Difficulty: Medium
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of原创 2017-10-12 14:04:10 · 207 阅读 · 0 评论 -
515. Find Largest Value in Each Tree Row Difficulty: Medium
You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]算法分析:考查BFS,或者说是树的层序遍历,但要注意区分每一层。我原创 2017-10-13 15:42:28 · 220 阅读 · 0 评论 -
136. Single Number Difficulty: Medium
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 me原创 2017-10-14 09:49:01 · 194 阅读 · 0 评论 -
442. Find All Duplicates in an Array Difficulty : Medium
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra space原创 2017-10-10 19:17:07 · 248 阅读 · 0 评论 -
463. Island Perimeter Difficulty : Easy
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely s原创 2017-10-03 11:46:40 · 206 阅读 · 0 评论 -
669. Trim a Binary Search Tree Difficulty : Easy
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result原创 2017-10-03 10:57:08 · 194 阅读 · 0 评论 -
476. Number Complement 难度:简单
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note: 1. The given integer is guaranteed to fit within the range of a 3原创 2017-09-24 11:14:44 · 557 阅读 · 0 评论 -
461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note: 0≤x,y<2310 ≤ x, y <原创 2017-09-16 17:12:55 · 204 阅读 · 0 评论 -
文章标题
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 from原创 2017-09-17 17:19:11 · 182 阅读 · 0 评论 -
657. Judge Route Circle-Difficulty:Easy
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 a原创 2017-09-17 19:54:25 · 242 阅读 · 0 评论 -
617. Merge Two Binary Trees; Difficulty:Easy
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree. T原创 2017-09-18 16:33:52 · 393 阅读 · 0 评论 -
561. Array Partition I; Difficulty : Easy
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl原创 2017-09-18 17:19:35 · 405 阅读 · 0 评论 -
500. Keyboard Row 难度:简单
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.Example 1:Input: ["Hello", "Alaska", "Dad", "Peace"]Outp原创 2017-09-27 16:39:33 · 227 阅读 · 0 评论 -
557. Reverse Words in a String III 难度:简单
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"Output原创 2017-09-28 16:04:04 · 341 阅读 · 0 评论 -
566. Reshape the Matrix Difficult : Easy
In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dimensio原创 2017-10-03 10:09:41 · 240 阅读 · 0 评论 -
226. Invert Binary Tree Difficult: Easy
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1算法分析:可以用层序遍历的方法交换左右子树,也可以直接递归。C语言版struct TreeNode* invertTree(struct TreeNode* roo原创 2017-11-03 22:48:09 · 220 阅读 · 0 评论