自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(36)
  • 收藏
  • 关注

原创 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 non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you

2017-12-12 17:15:57 146

原创 696. Count Binary Substrings

Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively.Sub

2017-12-11 21:38:05 271

原创 226. Invert Binary Tree

Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1递归遍历交换节点即可

2017-12-06 14:09:56 144

原创 637. Average of Levels in Binary Tree

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explan

2017-12-05 16:22:21 134

原创 443. String Compression

Given an array of characters, compress it in-place.The length after compression must always be smaller than or equal to the original array.Every element of the array should be a character (not

2017-12-02 11:18:09 727

原创 566. Reshape the Matrix

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-dim

2017-11-30 14:55:32 125

原创 669. Trim a Binary Search Tree

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 r

2017-11-28 21:29:56 126

原创 628. Maximum Product of Three Numbers

Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24Note:

2017-11-27 11:13:51 112

原创 543. Diameter of Binary Tree

Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath between any two nodes in a tree. This path may or may no

2017-11-24 15:07:27 138

原创 561. Array Partition I

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 a

2017-11-22 17:11:16 128

原创 728. Self Dividing Numbers

A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also, a self-d

2017-11-20 13:41:28 1078 1

原创 Add to List 617. Merge Two Binary Trees

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

2017-11-19 19:14:14 123

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

2017-11-18 13:24:23 115

原创 136. 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. Could you implement it without using ext

2017-11-17 20:50:14 107

原创 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 = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass

2017-11-16 15:25:54 125

原创 371. Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.采取异或来记录相加不考虑进位,采取与门得到的数左移记录进位,并将结果相加,直到进位都为零。

2017-11-15 22:46:45 216

原创 690. Employee Importance

You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.For example, employee 1 is the leader of empl

2017-11-14 19:33:50 107

原创 algorithm chapter8 8.15

题8 .15容易想到将最大独立集问题规约到此题即可,以下证明:1、证明此题为NP问题  给定一组解,即两个节点集合,我们可以在多项式时间内验证该解2、证明此题为NP难问题  这里假设求任意图G(V,E)大小为d的独立集,我们令G1=G(V,E),G2=(V,∅),此时G2只有点无边这样将问题进行规约  若G存在大小为d的独

2017-07-06 15:38:45 206

原创 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:Integers in each row are sorted in ascending from left to right.Integers in

2017-07-05 20:16:20 133

原创 515. Find Largest Value in Each Tree Row

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]此题容易想到使用GFS方法遍历

2017-07-05 20:00:32 166

原创 72. Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:

2017-06-10 20:51:51 162

原创 20. Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va

2017-06-09 11:05:38 160

原创 606. Construct String from Binary Tree

You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "()". And yo

2017-06-07 16:36:35 250

原创 553. Optimal Division

Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position to change

2017-05-25 21:02:06 196

原创 583. Delete Operation for Two Strings

Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.Example 1:Input: "

2017-05-23 14:39:03 415

原创 395. Longest Substring with At Least K Repeating Characters

Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.Example 1:Input:s = "aaabb", k =

2017-05-22 11:50:55 226

原创 438. Find All Anagrams in a String

Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be lar

2017-05-21 18:12:26 183

原创 383. Ransom Note

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot

2017-05-21 11:15:41 225

原创 541. Reverse String II

Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of th

2017-04-22 16:04:16 190

原创 217. Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is

2017-04-15 13:41:27 189

原创 547. Friend Circles

There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, the

2017-04-08 19:37:34 523

原创 132. Palindrome Partitioning II

Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return

2017-03-27 12:25:02 191

原创 386. Lexicographical Numbers

Given an integer n, return 1 - n in lexicographical order.For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimize your algorithm to use less time and space. The input si

2017-03-19 16:04:26 233

原创 151. Reverse Words in a String

Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in

2017-03-12 14:07:42 171

原创 62. Unique Paths

Question: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

2017-03-04 15:29:41 210

原创 451. Sort Characters By Frequency

Problem Description:Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't'

2017-02-25 16:14:55 277

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除