自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Leetcode 7. Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321Hints: Have you thought about this? Here are some good questions to ask before coding. Bonus points for you

2017-01-24 05:24:17 165

原创 Leetcode 6. ZigZag Conversion

The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I GY

2017-01-24 04:28:44 183

原创 Leetcode 3. Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le

2017-01-23 14:27:09 144

原创 Leetcode 2. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it

2017-01-23 13:53:51 130

原创 Leetcode 1. Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example: Given nums = [2, 7, 11,

2017-01-23 13:13:48 196

原创 LeetCode 444. Sequence Reconstruction

Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. The org sequence is a permutation of the integers from 1 to n, with 1≤n≤1041 ≤ n ≤ 10^4. Reconstruction

2017-01-21 14:14:12 2535

原创 LeetCode 353. Design Snake Game

Design a Snake game that is played on a device with screen size = width x height. Play the game online if you are not familiar with the game.The snake is initially positioned at the top left corner (0,

2017-01-21 05:13:05 487

原创 LeetCode 271. Encode and Decode Strings

Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.Machine 1 (sender) has the function:str

2017-01-20 13:48:46 326

原创 LeetCode 163. Missing Ranges

Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing ranges. For example, given [0, 1, 3, 50, 75], return [“2”, “4->49”, “51->74”, “76->99”]s思路: 1. 又是一道有

2017-01-20 09:51:01 236

原创 LeetCode 418. Sentence Screen Fitting

Given a rows x cols screen and a sentence represented by a list of words, find how many times the given sentence can be fitted on the screen.Note:A word cannot be split into two lines. The order of wo

2017-01-20 09:01:27 827

原创 LeetCode 186.Reverse Words in a String II

Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters. The input string does not contain leading or trailing spaces and the words are always s

2017-01-20 05:30:21 300

原创 LeetCodev379. Design Phone Directory

Design a Phone Directory which supports the following operations:get: Provide a number which is not assigned to anyone. check: Check if a number is available or not. release: Recycle or release a num

2017-01-19 10:43:27 235

原创 LeetCode 333. Largest BST Subtree

Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes in it.Note: A subtree must include all of its descendants.

2017-01-19 10:01:08 525

原创 LeetCode 356. Line Reflection

Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given set of points.Example 1: Given points = [[1,1],[-1,1]], return true.Example 2: Given points = [[1,

2017-01-19 08:34:00 481

原创 LeetCode 161.One Edit Distance

Given two strings S and T, determine if they are both one edit distance apart.s思路: 1. 求两个字符串的distance和Edit Distance一样:增加一个字符、减少一个字符、修改一个字符。所以,先判断长度,如果长度差>1,则不是one edit distance;如果长度差==1,则两个string只有一个字

2017-01-19 04:36:53 280

原创 LeetCode 267. Palindrome Permutation II

Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.For example:Given s = “aabb”, return [“abba”, “baa

2017-01-18 15:10:03 381

原创 LeetCode 244. Shortest Word Distance II

This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would you o

2017-01-18 14:04:44 388

原创 LeetCode 277. Find the Celebrity

Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1people know him/her but he/she

2017-01-18 12:54:42 298

原创 LeetCode 314. Binary Tree Vertical Order Traversal

Given a binary tree, return the vertical order traversal of its nodes’ values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be from left to r

2017-01-18 09:53:19 408 1

原创 LeetCode 285. Inorder Successor in BST

Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in-order successor in the tree, return null.思路: 1. 如下图,如果要找4的下一个inorder

2017-01-18 08:49:20 262

原创 数据结构及算法: union find学习

才接触到union find, 刷题看到很多题都可以用这个数据结构来做。在网上查了一下,发现最容易理解的是quosa上的一个讲解,链接:https://www.quora.com/What-is-an-intuitive-explanation-of-union-find 以及自己模仿的做法:http://blog.csdn.net/xinqrs01/article/details/54571073

2017-01-16 15:06:13 552

原创 LeetCode 261. Graph Valid Tree

Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.For example:Given n = 5 and edges

2017-01-16 14:49:49 659

原创 LeetCode 361. Boom Enemy

Given a 2D grid, each cell is either a wall ‘W’, an enemy ‘E’ or empty ‘0’ (the number zero), return the maximum enemies you can kill using one bomb. The bomb kills all the enemies in the same row and

2017-01-16 09:03:41 444

原创 LeetCode 253. Meeting Rooms II

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],…] (si < ei), find the minimum number of conference rooms required.For example, Given [[0, 30],[5, 10],[15,

2017-01-16 06:44:01 1810

原创 LeetCode 247. Strobogrammatic Number II

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Find all strobogrammatic numbers that are of length = n.For example, Given n = 2, return [“11”

2017-01-15 15:46:12 200

原创 LeetCode 251. Flatten 2D Vector

Implement an iterator to flatten a 2d vector.For example, Given 2d vector =[ [1,2], [3], [4,5,6] ]By calling next repeatedly until hasNext returns false, the order of elements returned by ne

2017-01-15 14:57:48 301

原创 LeetCode 255. Verify Preorder Sequence in Binary Search Tree

Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.You may assume each number in the sequence is unique.Follow up: Could you do it using on

2017-01-15 13:54:55 366

原创 LeetCode 298. Binary Tree Longest Consecutive Sequence

Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections

2017-01-14 09:57:17 257

原创 LeetCode 250. Count Univalue Subtrees

Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example: Given binary tree, 5 / \ 1 5

2017-01-14 08:14:53 266

原创 LeetCode 254. Factor Combinations

Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an integer n and return all possible combinations of its factors.Note: Each combin

2017-01-14 04:07:43 407

原创 LeetCode 359. 3Sum Smaller

Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.For example, given nums

2017-01-13 14:13:40 504

原创 LeetCode 325. Maximum Size Subarray Sum Equals k

Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn’t one, return 0 instead.Example 1: Given nums = [1, -1, 5, -2, 3], k = 3, return 4. (becau

2017-01-13 13:16:36 354

原创 LeetCode 286. Walls and Gates

You are given a m x n 2D grid initialized with these three possible values.-1 - A wall or an obstacle. 0 - A gate. INF - Infinity means an empty room. We use the value 231−1=21474836472^{31} - 1 = 21

2017-01-13 10:34:13 194

原创 (未完成!)LeetCode 351. Android Unlock Patterns

[LeetCode] Android Unlock Patterns 安卓解锁模式Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock patterns of the Android lock screen, which

2017-01-13 10:05:29 296

原创 LeetCode 156. Binary Tree Upside Down

Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origina

2017-01-13 10:02:06 257

原创 LeetCode 360. Sort Transformed Array

Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f(x)=ax2+bx+c f(x) = ax^2 + bx + c to each element x in the array.The returned array must be in sorted

2017-01-13 07:47:39 265

原创 LeetCode 320. Generalized Abbreviation

Write a function to generate the generalized abbreviations of a word.Example:Given word = “word”, return the following list (order does not matter):[“word”, “1ord”, “w1rd”, “wo1d”, “wor1”, “2rd”, “w2d”

2017-01-12 13:23:05 676

原创 (未完成!)LeetCode 348. Design Tic-Tac-Toe 设计井字棋游戏

Design a Tic-tac-toe game that is played between two players on a n x n grid.You may assume the following rules:A move is guaranteed to be valid and is placed on an empty block. Once a winning conditi

2017-01-11 13:34:43 353

原创 LeetCode 294. Flip Game II

Problem Description:You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive “++

2017-01-11 13:24:15 888

原创 LeetCode 256. Paint House

There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the hou

2017-01-11 10:36:04 425

空空如也

空空如也

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

TA关注的人

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