自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

风小西的专栏

看球,踢球,码代码。

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

原创 TopCoder - SRM521 div1 500 RangeSquaredSubsets

Problem Statement  Given a real number n, a set of points P in the XY plane is called n-squared if it is not empty and there exists a square of side n in the XY plane with its sides parall

2015-08-27 10:13:51 561

原创 LeetCode - Read N Characters Given Read4 II - Call multiple times

The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the

2015-08-11 13:50:52 465

原创 LeetCode - Different Ways to Add Parentheses

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *.Example 1I

2015-08-03 17:58:20 383

原创 LeetCode - Shortest Palindrome (KMP)

Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exam

2015-08-03 16:18:23 359

原创 LeetCode - Word Search II

Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hor

2015-08-03 14:50:13 289

原创 LeetCode - Implement Trie (Prefix Tree)

Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.一开始用了unorered_map,有点慢,换了数组后快了点class TrieNode {p

2015-08-01 09:42:31 325

原创 LeetCode - Best Time to Buy and Sell Stock IV

Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactionsO(N^3)算法,dp[i][k]

2015-07-23 23:19:49 306

原创 LeetCode - The Skyline Problem

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as

2015-07-22 22:33:05 557

原创 LeetCode - Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0

2015-07-21 21:22:40 276

原创 LeetCode - Count Complete Tree Nodes

Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,

2015-07-21 13:44:52 306

原创 LeetCode - Sliding Window Maximum

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window

2015-07-20 11:10:11 553

原创 LeetCode - Basic Calculator & Basic Calculator II

Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em

2015-07-17 16:45:17 320

原创 LeetCode - Majority Element II

Majority Element II Total Accepted: 4935 Total Submissions: 23021My SubmissionsQuestion Solution Given an integer array of size n, find all elements that appear more than ⌊ n/3

2015-07-17 14:40:32 277

原创 LeetCode - Palindrome Linked List

Palindrome Linked List Total Accepted: 4904 Total Submissions: 20945My SubmissionsQuestion Solution Given a singly linked list, determine if it is a palindrome.Follow up:Coul

2015-07-16 13:51:15 388

原创 LeetCode - Reverse Linked List

Reverse Linked List Total Accepted: 27232 Total Submissions: 85395My SubmissionsQuestion Solution Reverse a singly linked list.非递归: ListNode* reverse

2015-07-16 13:27:39 263

原创 LeetCode - Largest Number (sort的cmp的写法)

Largest Number Total Accepted: 23153 Total Submissions: 146500My SubmissionsQuestion Solution Given a list of non negative integers, arrange them such that they form the largest

2015-07-15 14:03:49 457

原创 LeetCode - Dungeon Game

Dungeon Game Total Accepted: 11922 Total Submissions: 66851My SubmissionsQuestion Solution The demons had captured the princess (P) and imprisoned her in the bottom-right corner

2015-07-15 13:32:20 287

原创 LeetCode - Binary Search Tree Iterator

Binary Search Tree Iterator Total Accepted: 20470 Total Submissions: 69577My SubmissionsQuestion Solution Implement an iterator over a binary search tree (BST). Your iterator wil

2015-07-14 13:41:56 265

原创 LeetCode - Majority Element

Majority Element Total Accepted: 47480 Total Submissions: 134338My SubmissionsQuestion Solution Given an array of size n, find the majority element. The majority element is the e

2015-07-13 12:54:46 443

原创 LeetCode - Excel Sheet Column

Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 首先算出多少位,再

2015-07-10 00:21:05 597

原创 LeetCode - Maximum Gap 题解

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements

2015-01-27 12:56:06 324

原创 LeetCode - Gas Station 题解

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to

2015-01-26 22:42:08 265

原创 LeetCode - 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",Retu

2015-01-26 21:34:54 235

原创 LeetCode - Word Ladder II 题解

Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exi

2015-01-25 13:57:50 434

原创 LeetCode - Word Ladder 题解(各种最短路算法)

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m

2015-01-24 10:01:35 742

原创 LeetCode - Binary Tree Maximum Path Sum 题解

Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.

2015-01-23 14:12:26 282

原创 LeetCode - Best Time to Buy and Sell Stock III 题解

Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You ma

2015-01-23 13:41:34 319

原创 LeetCode - Maximal Rectangle 题解

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:用A[i][j]表示从i,j向上有多少个连续的1,之后可以转换成Largest Rectangle in Histogram

2015-01-20 22:14:14 309

原创 LeetCode - Largest Rectangle in Histogram 题解

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o

2015-01-20 21:38:23 334

原创 LeetCode - Interleaving String 题解

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret

2014-12-06 13:31:01 329

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

2014-12-05 21:23:55 295

原创 LeetCode - Longest Palindromic Substring 题解

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.分析:先把字符串每两个字符之

2014-12-02 11:52:08 329

原创 LeetCode - Permutation Sequnce 题解

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""213""231""3

2014-11-30 21:14:57 311

原创 LeetCode - Minimum Window Substring 题解

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN

2014-11-30 14:59:00 474

原创 LeetCode - Anagrams 题解

Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.分析:对我这种英语不好的人来讲,理解题意比做题更加困难(捂脸)。原题是要求把一系列字符串中由相同字母组成的字符串打印出来(顺序可以不同)。于是可以对每

2014-11-27 15:14:15 300

原创 LeetCode - Min Stack 题解

class MinStack {public: stack Stack; stack Min; void push(int x) { Stack.push(x); if(Min.empty() || x <= Min.top()) Min.push(x); } void pop() {

2014-11-22 22:32:55 351

原创 LeetCode - 3Sum 题解

Given 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 (a,b,c

2014-11-22 20:10:59 414

原创 LeetCode - Regular Experssion Matching 题解

class Solution {public: bool isMatch(const char *s, const char *p) { if(*p == '\0' ) return (*s == '\0'); if(*(p+1) == '*'){ do{ if(isMatch(

2014-11-20 20:56:48 287

原创 LeetCode - Text Justification 题解

Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i

2014-11-16 10:58:56 352

原创 LeetCode - sqrt 题解

Implement int sqrt(int x).Compute and return the square root of x.分析:牛顿迭代法求平方根。

2014-11-16 10:24:26 296

空空如也

空空如也

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

TA关注的人

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