- 博客(36)
- 资源 (4)
- 收藏
- 关注
原创 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity 代码:
2014-08-29 14:00:00 410
原创 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-08-29 13:55:18 461
原创 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is
2014-08-29 13:48:44 368
原创 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with
2014-08-29 13:47:47 454
原创 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-08-29 13:45:14 415
原创 Divide Two Integers
Divide two integers without using multiplication, division and mod operator. 思路:不能用乘除
2014-08-29 13:41:24 543
原创 Substring with Concatenation of All WordsTotal
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 an
2014-08-29 13:37:24 461
原创 BF算法和KMP算法
一.BF算法 BF算法是普通的模式匹配算法,BF算法的思想就是将目标串S的第一个字符与模式串P的第一个字符进行匹配,若相等,则继续比较S的第二个字符和P的第二个字符;若不相等,则比较S的第二个字符和P的第一个字符,依次比较下去,直到得出最后的匹配结果。 举例说明: S: ababcababa P: ababa BF算法匹配的步骤如下
2014-08-29 13:28:17 652
原创 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 valid b
2014-08-19 14:55:30 413
原创 Remove Nth Node From End of List
Given 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-08-19 14:25:23 490
原创 Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 代码:
2014-08-19 12:57:04 432
原创 Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 代码:
2014-08-19 12:54:41 466
原创 Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. 代码:
2014-08-19 12:52:09 351
原创 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 stri
2014-08-19 12:48:20 398
原创 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. 代码: import java.uti
2014-08-19 12:45:10 337
原创 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 exactly
2014-08-19 12:42:59 349
原创 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. 思路:
2014-08-19 12:35:05 360
原创 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 t
2014-08-15 12:52:46 341
原创 Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
2014-08-15 12:47:31 331
原创 Reverse digits of an integer.
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 代码:
2014-08-15 12:43:53 1142 2
原创 最长回文子串
首先讲讲什么是回文, 看看Wiki是怎么说的:回文,亦称回环,是正读反读都能读通的句子,亦有将文字排列成圆圈者,是一种修辞方式和文字游戏。回环运用得当,可以表现两种事物或现象相互依靠或排斥的关系, 比如madam,abba,这样正反都一样的串就是回文串。 今天要写的问题了就是在一个字符串中找出最长的回文字串,比如串:"abcdedabakml", 他的最长回文字串就是"abcdedaba"。一般
2014-08-14 15:17:11 401
原创 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-08-14 15:14:11 420
原创 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-08-13 14:31:49 403
原创 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. For
2014-08-13 12:42:42 368
原创 Median of Two Sorted Arrays
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)). s
2014-08-12 19:09:30 320
原创 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, where
2014-08-12 19:02:25 476
原创 poj 1166 The Clocks
Description |-------| |-------| |-------| | | | | | | | |---O | |---O | | O | | | | | | | |-------| |-------| |-------|
2014-08-11 13:42:24 597
原创 匈牙利匹配算法
匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名。匈牙利算法是基于Hall定理中充分性证明的思想,它是部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最大匹配的算法。 -------等等,看得头大?那么请看下面的版本: 通过数代人的努力,你终于赶上了剩男剩女的大潮,假设你是一位光荣的新世纪媒人,在你的手上有N个剩男,M个剩女,每个人都可能
2014-08-08 12:25:55 1383
原创 poj 1274 The Perfect Stall
Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all the stalls in the new barn are differen
2014-08-08 12:21:52 453
原创 poj 2392 Space Elevator
Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to
2014-08-07 21:37:49 426
原创 多重背包
本文包含的内容: 问题描述 基本思路(和完全背包类似) 转换为01背包问题求解(直接利用01背包) --------------------------------------------- 1、问题描述 已知:有一个容量为V的背包和N件物品,第i件物品最多有Num[i]件,每件物品的重量是weight[i],收益是cost[i]。 问题:在
2014-08-07 20:21:58 468
原创 完全背包
本文包含的内容: 问题描述 基本思路(直接扩展01背包的方程) 转换为01背包问题求解(直接利用01背包) O(VN)的算法 --------------------------------------------- 1、问题描述 已知:有一个容量为V的背包和N件物品,第i件物品的重量是weight[i],收益是cost[i]。 条件:每种物品都有无限件,能放多
2014-08-07 20:19:08 482
原创 01背包
01背包问题描述 已知:有一个容量为V的背包和N件物品,第i件物品的重量是weight[i],收益是cost[i]。 限制:每种物品只有一件,可以选择放或者不放 问题:在不超过背包容量的情况下,最多能获得多少价值或收益 相似问题:在恰好装满背包的情况下,最多能获得多少价值或收益 这里,我们先讨论在不超过背包容量的情况下,最多能获得多少价值或收益。 基本思路 01背包的特点:每种物品只
2014-08-07 19:57:03 682
原创 poj 1088 滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23
2014-08-06 12:33:49 363
原创 poj 1230 Pass-Muraille
Description In modern day magic shows, passing through walls is very popular in which a magician performer passes through several walls in a predesigned stage show. The wall-passer (Pass-Muraille) ha
2014-08-03 11:57:08 697
原创 poj 1083 Moving Tables
Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 200 rooms each on the north side and south s
2014-08-02 17:29:41 476
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人