自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

刘天的博客

主要以刷oj题为主

  • 博客(27)
  • 收藏
  • 关注

原创 Search a 2D Matrix问题及解法

问题描述: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 from left to right.The first inte

2017-07-31 09:10:31 168

原创 Set Matrix Zeroes问题及解法

问题描述:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is proba

2017-07-31 08:18:39 241

原创 Simplify Path问题及解法

问题描述:Given an absolute path for a file (Unix-style), simplify it.示例:path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"问题分析:将/ 和 / 之间的字符串分割出来,"." 可以直接忽略,每出现一个".."字串,根据

2017-07-30 15:32:43 351

原创 Minimum Path Sum问题及解法

问题描述:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down

2017-07-29 20:35:49 301

原创 Unique Paths II问题及解法

问题描述:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectivel

2017-07-29 19:57:48 391

原创 Unique Paths问题及解法

问题描述: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

2017-07-29 10:40:19 360

原创 Rotate List问题及解法

问题描述:Given a list, rotate the list to the right by k places, where k is non-negative.示例:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.问题分析:根据题意,先求出总的节点个数num,再确定需

2017-07-29 08:34:04 229

原创 Permutation Sequence问题及解法

问题描述:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""

2017-07-28 20:20:35 216

原创 Spiral Matrix II问题及解法

问题描述:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.示例:Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ],

2017-07-28 09:04:50 184

原创 Merge Intervals问题及解法

问题描述:Given a collection of intervals, merge all overlapping intervals.示例:Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].问题分析:将各个间隔按照start排序,依次比较前一个end和后一个的start,看是否可以合并

2017-07-28 08:49:29 330

原创 Jump Game问题及解法

问题描述:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.

2017-07-27 22:45:10 248

原创 Spiral Matrix问题及解法

问题描述:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.示例:Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]

2017-07-27 21:57:16 396

原创 Longest Harmonious Subsequence问题及解法

问题描述:We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of it

2017-07-26 13:06:31 218

原创 Range Addition II问题及解法

问题描述:Given an m * n matrix M initialized with all 0's and several update operations.Operations are represented by a 2D array, and each operation is represented by an array with two positive 

2017-07-26 10:29:00 239

原创 Minimum Index Sum of Two Lists问题及解法

问题描述:Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common inter

2017-07-26 10:12:08 286

原创 Can Place Flowers问题及解法

问题描述:Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would

2017-07-26 09:27:14 340

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

2017-07-26 08:44:28 254

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

2017-07-24 13:38:14 233

原创 Set Mismatch问题及解法

问题描述:The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in re

2017-07-24 12:37:48 330

原创 Maximum Average Subarray I问题及解法

问题描述:Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value.示例:Input

2017-07-23 17:01:56 264

原创 Sum of Square Numbers问题描述

问题描述:Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.示例:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5Input: 3Out

2017-07-23 09:59:12 281

原创 Maximum Product of Three Numbers问题解法

问题描述:Given an integer array, find three numbers whose product is maximum and output the maximum product.示例:Input: [1,2,3]Output: 6Input: [1,2,3,4]Output: 24问题分析:本题求解一个数组中三个元素的积的最大值,

2017-07-23 09:19:24 313

原创 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.示例:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explanat

2017-07-22 20:19:41 357

原创 Multiply Strings问题及解法

问题描述:Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only

2017-07-22 19:27:49 358

原创 Pow(x, n)问题及解法

问题描述:Implement pow(x, n).问题分析:对一个数求幂运算,我们可以把他的幂分解开来,利用二分法,降低时间复杂度。过程详见代码:class Solution {public: double myPow(double x, int n) { return myPow2(x, n); } double myPow2(double

2017-07-22 08:14:33 1747

原创 Group Anagrams问题及解法

问题描述:Given an array of strings, group anagrams together.示例:Given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]问题分析:采用map数据结

2017-07-02 13:10:40 305

原创 Rotate Image问题及解法

问题描述:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).问题分析:矩阵顺时针旋转90度可以分为两步:1.对矩阵转置2.对矩阵按列reverse(翻转)过程详见代码:class Solution {publ

2017-07-01 09:37:32 824

空空如也

空空如也

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

TA关注的人

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