自定义博客皮肤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题为主

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

原创 Construct the Rectangle问题及解法

问题描述:For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose

2017-04-29 17:42:32 341

原创 Next Greater Element I问题及解法

问题描述:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding place

2017-04-29 17:06:17 307

原创 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.示例:Input: ["Hello", "Alaska", "Dad",

2017-04-28 15:35:24 584

原创 Max Consecutive Ones问题及解法

问题描述:Given a binary array, find the maximum number of consecutive 1s in this array.Note:The input array will only contain 0 and 1.The length of input array is a positive integer and will not

2017-04-28 13:56:41 308

原创 Minimum Moves to Equal Array Elements问题及解法

问题描述:Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.示例:Input:[1,2,3]

2017-04-26 16:55:58 195

原创 KMP问题详解

本博客主要是提供一个讲解连接,方便自己以后查看KMP算法详解

2017-04-26 11:11:02 281

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

2017-04-24 15:49:14 341

原创 Heaters问题及解法

问题描述:Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.Now, you are given positions of houses and heaters on a hori

2017-04-24 10:56:11 289

原创 Assign Cookies问题及解法

问题描述:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum si

2017-04-22 10:18:23 209

原创 Number of Boomerangs问题及解法

问题描述:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the

2017-04-22 09:42:32 309

原创 Arranging Coins问题及解法

问题描述:You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be form

2017-04-19 10:54:06 270

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

2017-04-19 10:12:30 249

原创 Path Sum III问题及解法

问题描述:You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, b

2017-04-18 15:36:37 470

原创 Number of Segments in a String问题及解法

问题描述:Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain any non-printable chara

2017-04-18 13:44:45 369

原创 Find All Numbers Disappeared in an Array问题及解法

问题描述:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this arr

2017-04-18 10:07:46 197

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

2017-04-17 15:10:36 784

原创 Island Perimeter问题及解法

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

2017-04-16 20:03:43 226

原创 Number Complement问题及解法

问题描述:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the

2017-04-16 19:40:00 298

原创 Binary Watch问题及解法

问题描述:A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least signific

2017-04-16 16:30:09 249

原创 Longest Palindrome问题及解法

问题描述:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example de >"Aa"

2017-04-16 16:29:18 308

原创 Convert a Number to Hexadecimal问题及解法

问题描述:Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in hexadecimal (de >a-fde>) must be in lowerc

2017-04-16 16:27:57 345

原创 Third Maximum Number问题及解法

问题描述:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).示例:Example 1:

2017-04-16 16:26:58 519

原创 Nth Digit问题及解法

问题描述:Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:n is positive and will fit within the range of a 32-bit signed integer (n 31).示例:Input

2017-04-16 16:24:55 334

原创 Fizz Buzz问题及解法

问题描述:Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “

2017-04-16 16:23:17 5272

原创 Add Strings问题及解法

问题描述:Given two non-negative integers de >num1de> and de >num2de> represented as string, return the sum of de >num1de> and de >num2de>.Note:The length of both de >num1de> and de >num2de> is

2017-04-16 16:22:14 792

原创 Sum of Left Leaves问题及解法

问题描述:Find the sum of all left leaves in a given binary tree.示例: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24

2017-04-11 14:24:04 313

原创 Find the Difference问题及解法

问题描述:Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter th

2017-04-11 08:54:01 584

原创 First Unique Character in a String问题及解法

问题描述:Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.示例:s = "leetcode"return 0.s = "loveleetcode",return 2.问题分析:记录字

2017-04-09 10:13:45 232

原创 Ransom Note问题及解法

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

2017-04-09 09:35:15 327

原创 Guess Number Higher or Lower问题及解法

问题描述:We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is

2017-04-09 09:08:51 270

原创 Sum of Two Integers问题及解法

问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.示例:Given a = 1 and b = 2, return 3.问题分析:不用+和-,我们可以考虑从位运算的角度出发。主要用到了进位操作和异或运算.

2017-04-07 12:46:42 241

原创 Intersection of Two Arrays II问题及解法

问题描述:Given two arrays, write a function to compute their intersection.示例:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].问题分析:寻找两个数组共同的元素,可重复。可以利用map把nums1中的元素出现次数记录下来,跟nums2

2017-04-07 10:50:48 388

原创 Power of Four问题及解法

问题描述:Given an integer (signed 32 bits), write a function to check whether it is a power of 4.示例:Given num = 16, return true. Given num = 5, return false.问题分析:一个数若是4的幂,那么它一定是2的幂,而且转换成二进制时

2017-04-07 09:08:21 309

原创 Intersection of Two Arrays问题及解法

问题描述:Given two arrays, write a function to compute their intersection.示例:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].问题分析:求解两个数组的交集,可利用map记录下nums1中有哪些元素,然后跟nums2中的元素匹配,看哪些元素

2017-04-06 15:53:18 382

原创 Valid Perfect Square问题及解法

问题描述:Given a positive integer num, write a function which returns True if num is a perfect square else False.示例:Input: 16Returns: TrueInput: 14Returns: False问题分析:我们可以利用二分查找法看看是否存在num

2017-04-06 15:29:32 219

原创 Reverse Vowels of a String问题及解法

问题描述:Write a function that takes a string as input and reverse only the vowels of a string.示例:Given s = "hello", return "holle".Given s = "leetcode", return "leotcede".问题分析:我们使用双指针,一个向

2017-04-06 14:51:28 242

原创 Reverse String问题及解法

问题描述:Write a function that takes a string as input and returns the string reversed.示例:Given s = "hello", return "olleh".过程很简单,直接看代码即可class Solution {public: string reverseString(str

2017-04-05 16:48:36 227

原创 Power of Three问题及解法

问题描述:Given an integer, write a function to determine if it is a power of three.Follow up:Do it without using any loop / recursion.问题分析:在有符号整数范围内,所有的3的幂均可被最大的3的幂数整除。这里3的最大幂是19,即最大3的幂数是11622

2017-04-05 10:42:38 297

原创 Word Pattern问题及解法

问题描述:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in

2017-04-04 11:27:26 1167

原创 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.示例:given nums = [0, 1, 0, 3, 12], after calling your f

2017-04-04 10:19:43 483

空空如也

空空如也

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

TA关注的人

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