- 博客(38)
- 收藏
- 关注
原创 【leetcode 排列组合问题】Next Permutation | Permutations | Permutations II | Permutation Sequence
leetcode上关于数字排列组合问题有四个,分别是:(1)Next Permutation :已知一个数组代表某个排列组合,求出比其代表的数字大的下一个排列组合,通过重组数组中的数字实现(2)Permutations:已知一组数字,求出所有可以表示出的排列组合(3)Permutations II:已知一组数字可能包含重复,求出所有可以表示出的排列组合(无重复的)(4)Permut
2014-09-03 23:02:20
941
原创 【leetcode】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
2014-09-03 22:51:47
434
原创 【leetcode】Divide Two Integers
题目:Divide two integers without using multiplication, division and mod operator.解析:
2014-08-31 22:33:52
793
原创 【leetcode KMP算法实现】Implement strStr()
题目:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.解析:实现strStr()方法,给定字符串haystack和needle,
2014-08-31 21:51:16
692
原创 【leetcode】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 n
2014-08-31 16:18:14
459
原创 【leetcode 移除有序序列重复数字】Remove Duplicates from Sorted Array(List) I(II)
leetcode上有四道关于移除有序序列中重复数字的题目,其中两道为数组结构,两道为链表结构,分别为:(1)Remove Duplicates from sorted array I:移除一个有序数组中的重复数字,并且返回新数组的大小。(2)Remove Duplicates from sorted array II:移除一个有序数组中的重复数字,并且返回新数组的大小,和上道题目不同的是每
2014-08-29 16:32:22
738
原创 【leetcode 链表相关】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
2014-08-29 11:21:34
463
原创 【leetcode】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 cons
2014-08-29 10:19:52
419
原创 【leetcode】Merge k Sorted Lists (归并排序)
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解析:合并k个有序链表,最后返回一个总的有序链表,分析并描述其复杂度。该题的实质为归并排序,平均时间复杂度为O(NlogN)。
2014-08-29 10:07:20
668
原创 【leetcode】括号符匹配问题(Parentheses):Valid Parentheses|Generate Parentheses|LongestValid Parentheses
leetcode上有三道关于括号符(‘(’,‘)’,‘[’,‘]’,‘{’,‘}’)匹配的问题,其中第三题是第一题的拓展,分别是:(1)Valid Parentheses,判断字符串是否是合法的括号匹配字符串(2)Generate Parentheses,根据所给的整数生成所有合法的括号匹配字符串(3)Longest Valid Parentheses,根据所给的括号字符串,求其中最长的括号匹配字符子串 下面分别讨论我对这三道题的思路的做法。
2014-08-28 17:09:59
3083
原创 【leetcode】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 fr
2014-08-28 16:58:19
602
原创 【leetcode】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:D
2014-08-28 16:17:08
372
原创 【leetcode】Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.解析:求字符串数组中所有数组的最长公共前缀,重点考察细节和边界条件,比如:[] :输入字符串数组为空,要判断if (strs .size() == 0)
2014-08-28 15:55:01
508
原创 【leetcode】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)
2014-08-26 23:39:30
482
原创 【leetcode】Regular Expression Matching
题目:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover th
2014-08-26 21:53:52
493
原创 【leetcode】String to Integer (atoi)
题目:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes: It is intended for this problem to be spe
2014-08-14 21:01:46
380
原创 【leetcode】Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.解析:将一个整形数字倒序输出,注意判断正负。这道题在华为面试的时候遇到过,很简单。
2014-08-14 21:01:19
596
原创 【leetcode】ZigZag Conversion
题目: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 for better legibility)P A H NA P L S I I GY I RAnd then read line by line: "PAHNAPLSIIG
2014-08-11 21:53:39
731
原创 【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.解析:求一个字符串的最长回文子串。有三种解法,并且时间不断在优化:解法一:暴力解法,遍历字符串,将每个字符做子串中心,向两端扩展,时间复杂度O(N^2
2014-08-10 11:40:56
377
原创 【leetcode】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 linked list.Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Outpu
2014-08-10 10:19:04
1021
原创 【leetcode】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 "bbbbb" the longest substring is "b", with the lengt
2014-08-08 23:39:06
590
原创 【leetcode】Median of Two Sorted Arrays
解析:求两个排序数组的中位数,数组长度分别是m和n,要求时间复杂度为O(log(m+n))。刚开始思路是利用类似合并排序的思路分别遍历两个数组,但是算法复杂度为O(n)。查看网上的解题方法,原问题其实是一个寻找第k小数的问题,中位数实际上是第(m+n)/2小的数。对于数组a和b,比较A的第k/2小的元素A[k/2-1]和B的第k/2小的元素B[k/2-1]两个元素,有三种情况可以考虑:1. A[k/2-1]<B[k/2-1]表示A[0]到A[k/2-1]的元素都在A和B合并之后的前k小的元素中,可以把A
2014-08-07 22:53:09
426
原创 【leetcode X Sum 系列】Two Sum|3Sum|3Sum Closest|4Sum
Two Sum 题目:My SubmissionsGiven 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 index1 must be less than ind
2014-08-07 20:40:47
882
原创 Java实现堆排序
public class HeapSort { /** * @param args */ public static void main(String[] args) { int[] a = { 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 }; heapSort(a); for (int in : a) { System.out.print(in
2014-08-06 20:42:06
559
原创 【leetcode】Surrounded Regions
类似于中国围棋的二维字符数组,将被'X'包围的'O'全部转化为'X',不同的是,与边缘接轨的'O'不用转化为'X',所以切入点在于边缘的‘O’,从边缘开始做DFS或者BFS,由于用例有200*200的棋盘,使用Java写DFS会因为递归太多层报Stackoverflow的错误,用C++实现能够AC:
2014-08-04 20:08:03
564
原创 【初学python】错误SSLError: [Errno 1] _ssl.c:504:的解决记录
最近在实习公司学习使用python做web自动化测试,其中使用到httplib这个模板,主要用于与待测试界面建立HTTP连接,发送数据请求,接收请求状态码和查询数据,验证功能。但是新版本的web界面改成使用https协议,原来的测试用例都变成无法跑通的状态。
2014-08-02 18:23:15
16543
1
原创 【leetcode】Balanced Binary Tree
题目:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node ne
2014-07-29 22:46:36
646
原创 【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 = "aadbbba
2014-07-23 20:15:03
434
原创 【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"]
2014-07-21 22:41:00
437
原创 【leetcode】Decode Ways
题目:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the
2014-07-21 21:25:44
432
原创 【leetcode】Container With Most Water
题目:给一组数组作为水池的高度,以其中两个高度作为水池的壁,求最大的水池容量。假设左边的壁为left,右边的壁为right,则水池容量capacity= (right-left)*min(height(right),height(right))定义两个指针left和right从数组两头开始遍历:如果left的高度低于right,则将left指针右移找
2014-07-17 15:33:31
540
原创 【leetcode】Roman to Integer | Integer to Roman
题目:【leetcode】12 Integer to Roman(将阿拉伯数字转换成罗马数字)
2014-07-17 15:32:32
507
原创 【leetcode】 Longest Common Prefix
求字符串数组中所有数组的最长公共前缀,代码很简单,但是要很注重细节边界值输入要特别注意,比如:[] 输入空的字符串数组,要判断 if (strs .size() == 0) return "";[""] 字符串数组里面只有一个空字符串等情况等等。
2014-07-17 15:24:37
478
原创 【leetcode】Spiral Matrix
今天在命令行用ant跑junit时候一直出现错误java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing查了很多资料,原来要将junit的jar包拷贝到ANT_HOME/lib下。但是之后错误还是存在,看到解释是版本问题,有提出要添加hamcrest.jar包的,试过没用。
2014-07-17 14:45:58
489
原创 【PAT Basic Level】1002 写出这个数
题目地址:http://pat.zju.edu.cn/contests/pat-b-practise/1002读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
2014-03-14 10:09:40
520
原创 【PAT Basic Level】1001 害死人不偿命的(3n+1)猜想
题目地址:http://pat.zju.edu.cn/contests/pat-b-practise/1001卡拉兹(Callatz)猜想:对任何一个自然数n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把(3n+1)砍掉一半。这样一直反复砍下去,最后一定在某一步得到n=1。卡拉兹在1950年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结
2014-03-14 09:50:41
580
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人