自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Magi Su的技术回收站

在虚构的故事当中寻求真实感的人脑袋一定有问题

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

原创 LeetCode题解: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 completel

2017-02-05 10:03:23 596

原创 LeetCode题解:Arithmetic Slices

A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequenc

2017-02-04 19:21:14 600

原创 LeetCode题解:FizzBuzz

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 “Buzz”.

2017-02-04 18:13:22 611

原创 LeetCode题解: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

2017-02-04 18:06:58 424

原创 LeetCode题解:Battleships in a Board

Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:You receive a valid

2017-02-04 17:47:19 455

原创 LeetCode题解: 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 range

2017-02-04 17:21:06 526

原创 LeetCode题解:Teemo Attacking

In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning tim

2017-02-04 15:59:23 412

原创 LeetCode题解: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 length L

2017-01-25 16:30:47 421

原创 LeetCode题解:Max Consecutive Ones

Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv

2017-01-20 16:17:07 448

原创 LeetCode题解:Magical String

A magical string S consists of only '1' and '2' and obeys the following rules:The string S is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates

2017-01-20 16:11:56 734

原创 LeetCode题解:Reverse String

Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".思路:当然可以用双指针来做,不过最简单的还使用STL。题解:std::string reverseString(st

2017-01-17 16:37:56 421

原创 LeetCode题解: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.思路:先通过异或得到

2017-01-17 16:33:44 440

原创 LeetCode题解:Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",

2017-01-17 13:17:26 349

原创 LeetCode题解: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 size of a c

2017-01-02 14:25:31 525 1

原创 LeetCode题解:Compare two version numbers version1 and version2.

Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and conta

2015-05-16 13:48:36 1036

原创 Levenshtein Edit distance

似乎在LeetCode里面也有,不过这里是为了解决另外的问题而做的。假设

2014-10-13 06:36:37 957

原创 PageRank的模拟计算

源于Stanford在Coursera上的Mining Massive Datasets课程。Week 1里的作业

2014-10-05 13:36:24 978

原创 LeetCode题解:Word Search

Word SearchGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontall

2014-01-13 05:54:54 1021

原创 LeetCode题解:Distinct Subsequences

Distinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences ofT in S.A subsequence of a string is a new string which is formed from the original string by

2014-01-08 13:07:15 838

原创 LeetCode题解:Candy

Candy There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have a

2014-01-07 14:26:16 1304 1

原创 LeetCode题解: Valid Number

Valid NumberValidate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement t

2013-12-16 13:12:06 1836

原创 LeetCode题解:Implement strStr()

Implement strStr()Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.思路:首先想到的是KMP算法。不过似乎不是很成功,提交了之后总是报Runtime error

2013-12-16 06:37:53 2091

原创 Amazon DynamoDB的模型

Amazon的DynamoDB是一个NoSQL类型的数据库。数据库(Database)是由表(Table)组成的。每个表则由项(Item)组成。每一项包含任意个属性(Attribute),但是总共大小不能超过64KB。每个属性都是一个名字/值组成的对(name/value pair)。每一个Item均有一个主键(Primary Key)。主键分两种类型,一种是哈希(Hash)类型,

2013-12-11 14:07:36 1133

原创 LeetCode题解:LRU Cache

LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:get and set.get(key) - Get the value (will always be positive) of

2013-12-02 16:24:01 1849 2

原创 LeetCode题解:Wildcard Matching

Wildcard MatchingImplement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The ma

2013-11-30 03:35:09 1188

原创 LeetCode题解:Sqrt(x)

Sqrt(x) Implement int sqrt(int x).Compute and return the square root of x.思路:可以考虑二分搜索,但是二分搜索的起点不好判定,不过可以预先计算好numeric_limits::max()的平方根,然后搜索,这样范围就缩小很多而且避免了溢出。有的人用long来计算,这样在很多情况下也是可以避免溢出的。但是必

2013-11-29 05:10:12 1608

原创 LeetCode题解:Divide Two Integers

Divide Two IntegersDivide two integers without using multiplication, division and mod operator.思路:核心思想是:令试除数等于除数,如果试除数小于被除数,那么试除数乘二,商乘二,继续比较;否则试除数除二,商除二,被除数减去试除数,重新开始。这其实就是类似二分搜索法。题目有一些边边角

2013-11-29 04:42:14 883

原创 LeetCode题解:Evaluate Reverse Polish Notation

Evaluate Reverse Polish NotationEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.

2013-11-28 03:43:50 3444 1

原创 LeetCode题解:Search in Rotated Sorted Array

Search in Rotated Sorted ArraySuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to searc

2013-11-26 07:02:34 1624

原创 LeetCode题解: Search for a Range

Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the

2013-11-26 06:10:53 889

原创 LeetCode题解:Surrounded Regions

Surrounded RegionsTotal Accepted: 1947 Total Submissions: 13017 Given a 2D board containing 'X' and 'O', capture all regions surrounded by'X'.A region is captured by flipping all 'O's into '

2013-11-26 04:18:02 1258

原创 LeetCode题解: Reverse Linked List II

Reverse Linked List IIReverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:

2013-11-26 03:41:01 3697 3

原创 LeetCode题解: Construct Binary Tree from Preorder and Inorder Traversal

Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tre

2013-11-25 15:07:45 903

原创 LeetCode题解: Construct Binary Tree from Inorder and Postorder Traversal

Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tre

2013-11-25 14:47:42 1207

原创 LeetCode题解:Decode Ways

Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine t

2013-11-25 13:52:04 2402

原创 LeetCode题解:Combinations

CombinationsGiven two integers n and k, return all possible combinations ofk numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1

2013-11-25 03:58:10 813

原创 LeetCode题解:3sum closest

3Sum ClosestGiven an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input

2013-11-25 00:48:54 1249 1

原创 LeetCode题解:Combination Sum I and II

Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen fro

2013-11-25 00:29:12 1191 1

原创 LeetCode题解:3Sum

3SumGiven an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (

2013-11-24 15:22:50 1239 1

原创 LeetCode题解:Merge/Insert Interval

Merge IntervalsGiven a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].Insert IntervalGiven a

2013-11-24 06:36:59 1142 1

空空如也

空空如也

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

TA关注的人

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