自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(36)
  • 资源 (1)
  • 收藏
  • 关注

原创 leetcode Roman Integer

class Solution { public: int romanToInt(string s) { if (s.length() < 1) return 0; map m; m['I'] = 1; m['V'] = 5; m['X'] = 10; m['L'] = 50; m['C'] = 100; m['D'] = 500; m['M'] =

2013-10-31 21:59:06 804

原创 leetcode Remove Nth Node From End of List

Use two pointers and the first pointer move forwards n steps first./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)

2013-10-31 17:06:33 771

原创 Leetcode 25 Reverse Nodes in k-Group 插入到每组头部,链表容易插

Two problems:1. Counting the length is much easier than reversing the last less than k nodes.2. Don't forget:lastGroupTail->next = p;/** * Definition for singly-linked list. *

2013-10-30 23:57:07 808

原创 leetcode Divide Two Integers

There are two major problems:1. The minimal int is also a test case, so long long is essential. 2. return (1>1), divisor); is wrong because of the priority. The right code is :class Solution

2013-10-30 21:46:44 1066

原创 leetcode Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be only one unique solution.class Solution {...

2013-10-29 22:26:10 1056

原创 LeetCode 44 Wildcard Matching 贪心 DP

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

2013-10-29 17:14:09 2263

原创 Leetcode 47. Permutations II next_perm 下一个排列 注意包含重复的情况

I'll introduce a method without using the permutation tree.From the right to the left, find the first num[i-1] < num [i], record ii = i-1;Find the minimal number larger than num[ii] from ii's ...

2013-10-27 21:07:00 1018

原创 leetcode Rotate Image

You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the imagein-place, which means you have to modify the input 2D matrix d...

2013-10-27 16:46:45 937

原创 leetcode 56. Merge Intervals 759. Employee Free Time 不用线段树

Given 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].First, this is not a problem about segment tree. D...

2013-10-26 15:52:33 833

原创 leetcode 57 Insert Interval

First, this problem isn't about segment tree. Second, I wanna share a terrible code without using the function insert and considering the case [[3,5],[12,15]], [6,6]/** * Definition for an inter

2013-10-26 14:49:10 1075

原创 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"()", whi...

2013-10-26 00:35:12 1085

原创 leetcode Valid Number

Validate 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 to be ambig...

2013-10-25 16:50:24 760

原创 leetcode Text Justification

I'm slow in handling these long description, so it's necessary to ask for an input/output case from the interview. Another mistake is that I overview the last line "For the last line of text, it sho

2013-10-24 23:38:21 1497

原创 leetcode Sqrt(x) Binary Search

Pay attention to that mid * mid may be larger than int. So long long is enough. class Solution { public: int sqrt(int x) { // Note: The Solution object is instantiated only once and is reus

2013-10-24 20:48:03 923

原创 leetcode 4Sum Summary for unique and duplicates

We should pay attention to the duplicates in this problem. STL offers a way to be unique: class Solution {public: vector > fourSum(vector &num, int target) { vector > ret; if(num.size() < 4)

2013-10-24 12:20:28 1011

原创 leetcode implement strStr

I wanna make a summary for KMP. Next[j] means that  max{ Next[j]| needle[j-Next[j]..j-1] == needle[0..Next[j]-1] }, i.e.,at most k characters before needle[j] are matching the first k characters o

2013-10-24 00:12:45 1196

原创 leetcode 84 Search in Rotated Sorted Array II 二分循环变种

Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the a...

2013-10-20 22:57:39 900 1

原创 leetcode Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1-&...

2013-10-20 16:38:44 778

转载 leetcode Largest Rectangle in Histogram

Givennnon-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 of e...

2013-10-20 00:28:31 715

原创 leetcode Scramble String

Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr...

2013-10-18 23:10:19 1220

原创 leetcode Decode Ways I & II Divide and Conquer

A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the...

2013-10-18 22:15:08 1051

转载 leetcode Gray Code

常用位操作:(a) 将第27位设置为及格(设作1)其他位不变:   result|=(1(b) 将第27位设置成不及格(设为0)。   result&=~(1(c) 反转第27位的值。   result^=(1[解题思路]看到这个题时,首先做了一个模拟,当n=3时,gray code应该是000001011010

2013-10-18 19:18:12 923

原创 leetcode Subsets II

Take advantage of the order to eliminate the duplicate sets. The following is the code: class Solution { public: vector> res; void subsets(vector& S, int start, vector& numset) { if (star

2013-10-18 15:06:19 1164

原创 leetcode Reverse Linked List II

For this type of question, two things should be paid attention to: If the first node is the head, take case of the predecessor of head. If the first node is the head, take case of the returning

2013-10-17 20:10:50 708

原创 leetcode Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order do...

2013-10-17 17:58:10 776

原创 leetcode Unique Binary Search Trees II

Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3...

2013-10-17 14:28:51 772

原创 leetcode Recover Binary Search Tree

Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise ...

2013-10-17 00:02:33 1271

原创 leetcode Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the ...

2013-10-16 11:11:17 1408

原创 leetcode Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 ...

2013-10-15 15:26:30 1068

原创 leetcode Distinct Subsequences DP

Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none)

2013-10-15 11:20:53 1095

原创 Populating Next Right Pointers in Each Node II

Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant ext...

2013-10-15 09:45:39 810

原创 leetcode Best Time to Buy and Sell Stock III

Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not en...

2013-10-14 15:14:07 1262

原创 leetcode Best Time to Buy and Sell Stock II

We should buy the stock at the starting point of ascending status, and sell the stock at the ending point of ascending status. The code is :class Solution {public: int maxProfit(vector &price

2013-10-14 14:56:28 937

原创 leetcode Binary Tree Maximum Path Sum

Binary Tree Maximum Path Sum Total Accepted: 3538 Total Submissions: 19408My SubmissionsGiven a binary tree, find the maximum path sum.The path may start and end at any node in the tree.

2013-10-12 00:26:17 1338

原创 leetcode Word Ladder II hash BFS

 Word Ladder II Total Accepted: 1447 Total Submissions: 17873My SubmissionsGiven two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such...

2013-10-09 20:35:00 1312

转载 【智力题】飞机加油问题

已知: 每个飞机只有一个油箱, 飞机之间可以相互加油(注意是相互,没有加油机) 一箱油可供一架飞机绕地球飞半圈,问题:为使至少一架飞机绕地球一圈回到起飞时的飞机场,至少需要出动几架飞机?(所有飞机从同一机场起飞,而且必须安全返回机场,不允许中途降落,中间没有飞机场)参考答案:3架飞机、5架次;飞行方案:A、B、C同时从机场出发,飞至1/8处,C给A、B分别加上1/8的油,自身还剩下1...

2013-10-08 14:54:24 3753

空空如也

空空如也

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

TA关注的人

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