LeetCode
文章平均质量分 77
讲解LeetCode思路和一些奇奇怪怪得解法
胖子程序员
穷学生一个
展开
-
[LeetCode][15]3Sum解析与快速排序算法-Java实现
Q: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: The solution set must原创 2016-06-17 09:14:29 · 1735 阅读 · 0 评论 -
[LeetCode][14]Longest Common Prefix解析 两种算法和底层源码的深入对比-Java实现
Q:Write a function to find the longest common prefix string amongst an array of strings.A:这题的大概意思就是说给你一组字符串找出其中最长的哪个通用的前缀出来。这个东西不难找,但是如何找的又快又好不简单。其实这题本来就是easy题,但是却让我联想到了《数据结构与算法分析》上的一道题目,那道题目是原创 2016-06-15 13:12:37 · 3955 阅读 · 3 评论 -
[LeetCode][13]Roman to Integer解析 罗马字符转int类型关于栈的常数实现-Java实现
Q:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.A:以下解法和代码没有借阅以往任何资料,如果有更好的解法请在评论区留言看到这一题我真是感叹城会玩,昨天刚刚解过一个int转罗马字母,今天又反过来解。原创 2016-06-14 10:36:50 · 2721 阅读 · 0 评论 -
[LeetCode][12]Integer to Roman解析 int转罗马字符时间复杂度为常数的实现-Java实现
Q:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.A:俺是真不知道啥是roman,我去查了一下合着是罗马字体,这题目意思也很简单就是说我要输入一个数字可以保证是1~3999但是你要把这个阿拉伯数字转原创 2016-06-13 09:57:08 · 1968 阅读 · 0 评论 -
[LeetCode][11]Container With Most Water解析 时间复杂度为O(n) -Java实现
Q: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,原创 2016-06-12 14:16:19 · 2228 阅读 · 0 评论 -
[LeetCode][10]Regular Expression Matching解析 -Java实现
Q:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire原创 2016-06-11 14:38:15 · 2854 阅读 · 0 评论 -
[LeetCode][9]Palindrome Number解析与StringBuilder.reverse()源码实现 -Java实现
Q:Determine whether an integer is a palindrome. Do this without extra space.A:这个题目说实话,我是后半句没有看懂的。。。这个without extra space不知道是不是单纯的只是不让用多余空间,如果我理解错了,希望有人能教我一下。。我们之前解过一个回文的题目回文,感觉这题是不是简单了点,上次用的原创 2016-06-10 20:11:43 · 2204 阅读 · 1 评论 -
[LeetCode][8]String to Integer (atoi)解析与模仿Java源码实现 -Java实现
Q: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原创 2016-06-07 12:19:18 · 1826 阅读 · 1 评论 -
[LeetCode][7]Reverse Integer解析与位运算实现 -Java实现
Q:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321A:以下解法和代码没有借阅以往任何资料,如果有更好的解法请在评论区留言这题我们很久之前就做过了,相当年我还只会C++的时候老师就布置这种题目给做了,当时的解法应该是先判断原创 2016-06-06 15:57:38 · 2006 阅读 · 1 评论 -
[LeetCode][6]ZigZag Conversion解析与特殊解法 -Java实现
Q: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原创 2016-06-06 14:29:53 · 3800 阅读 · 1 评论 -
[LeetCode][5]Longest Palindromic Substring解析 -Java实现
Q: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.A;以下解法和代码没有借原创 2016-06-05 13:48:00 · 1033 阅读 · 0 评论 -
[LeetCode][4]Median of Two Sorted Arrays解析 -Java实现
Q:There are two sorted arrays nums1 and nums2 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)).A:这个题目大致是说给你两个被排序原创 2016-06-04 20:25:59 · 608 阅读 · 0 评论 -
[LeetCode][3]Longest Substring Without Repeating Characters解析 -Java实现
A:Given a string, find the length of the longest substring without repeating characters.Q:以下解法和代码没有借阅以往任何资料,如果有更好的解法请在评论区留言大致意思就是给你一个字符串,找出里面最长的不重复的字符串。反正我的第一反应如下(灵感来源于Android源码中对双击,三击的判原创 2016-06-01 18:34:14 · 809 阅读 · 0 评论 -
[LeetCode][2]Add Two Numbers解析 -Java实现
Q: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原创 2016-06-01 16:34:44 · 3271 阅读 · 0 评论 -
[LeetCode][1]Two Sum解析 -Java实现
Q:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.A:以下解法和代码没有借阅以往任原创 2016-06-01 16:23:30 · 1754 阅读 · 0 评论