学习
文章平均质量分 60
ststns
这个作者很懒,什么都没留下…
展开
-
Median of two sorted array
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).原创 2014-10-06 10:00:12 · 348 阅读 · 0 评论 -
Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all vali原创 2014-10-23 12:57:00 · 216 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2014-10-07 12:11:22 · 275 阅读 · 0 评论 -
Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-10-07 13:37:47 · 329 阅读 · 0 评论 -
Remove Nth Node From End of List
iven a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2014-10-23 12:06:56 · 222 阅读 · 0 评论 -
Next Permutation
mplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2014-11-10 14:37:03 · 355 阅读 · 0 评论 -
Reverse digits of an integer.
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原创 2014-10-09 10:36:21 · 317 阅读 · 0 评论 -
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-10-08 13:29:50 · 265 阅读 · 0 评论 -
Single number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2014-10-09 14:05:42 · 309 阅读 · 0 评论 -
Search in Rotated Sorted Array
Suppose 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 search. If found in the array retur原创 2014-11-13 14:20:24 · 217 阅读 · 0 评论 -
Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-10-27 13:16:53 · 210 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.第一解,超时了。。。原创 2014-10-28 12:46:01 · 249 阅读 · 0 评论 -
String to Integer (atoi)
String to Integer (atoi) Total Accepted: 19082 Total Submissions: 130077My SubmissionsImplement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases原创 2014-10-10 13:30:19 · 340 阅读 · 0 评论 -
Search for a Range
Given 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 target is not found原创 2014-11-13 14:46:43 · 245 阅读 · 0 评论 -
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 "()",原创 2014-11-13 13:36:51 · 244 阅读 · 0 评论 -
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-10-10 13:39:04 · 323 阅读 · 0 评论 -
Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2014-11-13 15:27:43 · 243 阅读 · 0 评论 -
Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-10-28 13:24:21 · 252 阅读 · 0 评论 -
Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2014-11-14 15:16:27 · 242 阅读 · 0 评论 -
Reverse Nodes in k-Group
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *reve原创 2014-10-30 13:38:21 · 343 阅读 · 0 评论 -
Regular Expression Matching
'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(c原创 2014-10-13 01:57:55 · 299 阅读 · 0 评论 -
Container With Most Water
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two原创 2014-10-14 12:58:09 · 254 阅读 · 0 评论 -
Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2014-11-01 13:29:37 · 240 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
看到一个很秀逗的解法。。。贴一下原创 2014-10-31 14:14:59 · 215 阅读 · 0 评论 -
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.A sudoku原创 2014-11-18 15:11:24 · 238 阅读 · 0 评论 -
Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.网上都比较喜欢用recursion,我个人觉得脱了裤子放屁。。。。原创 2014-10-15 12:21:38 · 248 阅读 · 0 评论 -
Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.罗马数字,左减右加,从后往前扫,和5xx比较原创 2014-10-15 12:57:54 · 242 阅读 · 0 评论 -
Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.这个题没什么ji'qiao原创 2014-10-16 13:00:14 · 187 阅读 · 0 评论 -
Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2014-11-19 14:14:06 · 203 阅读 · 0 评论 -
Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这个substring的题目以前做并行搜索的时候用过boyer-moore的yang原创 2014-11-03 13:28:41 · 225 阅读 · 0 评论 -
Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2014-10-05 14:04:34 · 579 阅读 · 0 评论 -
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-10-17 12:36:19 · 274 阅读 · 0 评论 -
Combination Sum II
class Solution {public: vector > combinationSum2(vector &candidates, int target) { vector solution; vector > res; int sum=0; sort(candidates.begin(),candidates.end());原创 2014-11-25 14:41:22 · 210 阅读 · 0 评论 -
3Sum Closest
Given 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 would have exact原创 2014-10-20 13:33:01 · 234 阅读 · 0 评论 -
Divide Two Integers
Divide two integers without using multiplication, division and mod operator.原创 2014-11-05 14:43:07 · 222 阅读 · 0 评论 -
4Sum
#include #include using namespace std;class Solution {public: vector > fourSum(vector &num, int target) { vector > ct; int size=num.size(); if (size<4) return ct; sor原创 2014-10-21 13:08:46 · 237 阅读 · 0 评论 -
Combination Sum
iven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numbe原创 2014-11-21 14:38:54 · 270 阅读 · 0 评论 -
Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2014-10-22 13:14:28 · 185 阅读 · 0 评论 -
Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without原创 2014-11-06 15:39:53 · 240 阅读 · 0 评论 -
string multiplication
和我们正常做乘法一样,从后往前乘,考虑当前两个位数,余数和进数以及已经算出来的结果不停地update结果就可以了。唯一有问题的就是考虑前面位数为000的时候,要重新扫一遍。#include #include using namespace std;class Solution {public: string multiply(std::string num1, std::s原创 2015-01-07 16:00:51 · 290 阅读 · 0 评论