随笔分类 -  leetcode and POJ

摘要:Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Fo... 阅读全文

posted @ 2015-05-14 16:42 lysuns 阅读(217) 评论(0) 推荐(0)

摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文

posted @ 2015-05-05 15:12 lysuns 阅读(211) 评论(0) 推荐(0)

摘要:解决数独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 ... 阅读全文

posted @ 2015-04-24 17:20 lysuns 阅读(202) 评论(0) 推荐(0)

摘要: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 valu... 阅读全文

posted @ 2015-04-24 14:49 lysuns 阅读(153) 评论(0) 推荐(0)

摘要:Longest Valid ParenthesesGiven a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substr... 阅读全文

posted @ 2015-04-20 17:35 lysuns 阅读(164) 评论(0) 推荐(0)

摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文

posted @ 2015-04-20 16:54 lysuns 阅读(206) 评论(0) 推荐(0)

摘要: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 endpo... 阅读全文

posted @ 2015-04-17 16:34 lysuns 阅读(165) 评论(0) 推荐(0)

摘要:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font ... 阅读全文

posted @ 2015-04-17 10:06 lysuns 阅读(209) 评论(0) 推荐(0)

摘要:最长回文子串:1. 暴力搜索 时间复杂度O(n^3)2. 动态规划dp[i][j] 表示子串s[i…j]是否是回文初始化:dp[i][i] = true (0 i) ? min(p[j], mx-i) : 0; while (cstr[i + p[i] + 1] == cs... 阅读全文

posted @ 2015-04-10 17:17 lysuns 阅读(225) 评论(0) 推荐(0)

摘要:Problem 2 ---Add Two Numbers简单的模拟题。Problem 3 ---Longest Substring Without Repeating Characters题意: 给定一个字符串序列,找出最长无重复的子序列。如"abcabcbb"的最长不重复子序列为"abc"思路: ... 阅读全文

posted @ 2015-04-10 17:00 lysuns 阅读(185) 评论(0) 推荐(0)

摘要:很简单。没什么好说的。但是在阿里实习的第四面的时候居然问到了。大意是给出一组无序数列和目标数Z,在无序数列中找到X和Y,使得X+Y=Z。有两种方法: 一种是排序后,同时首尾搜索。时间复杂度为O(nlgn) + O(n) = O(nlgn)。空间复杂度为O(1) 另一种是把公式转换为X = Z-Y... 阅读全文

posted @ 2015-02-20 15:24 lysuns 阅读(337) 评论(0) 推荐(0)

导航