
LeetCode
文章平均质量分 59
满脸猪头肉
四肢健全,头脑发热,吃嘛嘛香
展开
-
【leetcode with java】1 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原创 2015-04-11 14:54:32 · 527 阅读 · 0 评论 -
【leetcode with java】7 Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Tags: Math【思路】唯一需要注意的是正负号和边界(MAX_VALUE和MIN_VALUE)的判断【上码】public cla原创 2015-05-07 16:56:34 · 518 阅读 · 0 评论 -
【leetcode with java】32 Longest Valid Parentheses O(n)
这个题目leetcode上提示用动态规划,但是那样要O(n^2)。我自己想出了一个O(n)的算法,并提交通过。【题目】Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "((原创 2015-05-06 10:15:45 · 703 阅读 · 0 评论 -
【leetcode with java】6 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原创 2015-04-27 18:13:21 · 438 阅读 · 0 评论 -
【leetcode with java】8 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 case原创 2015-05-08 09:27:35 · 557 阅读 · 0 评论 -
【leetcode with java】18 4Sum O(n^2)
我看了几个人气比较高的博客,他们这个算法都没做到O(n^2),所以提前将我的解法贴出来分享,供大家参考(前面略过的题目近期都会补上的)。【题目】: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 uniqu原创 2015-04-24 16:35:55 · 1249 阅读 · 0 评论 -
【leetcode with java】3 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原创 2015-04-15 17:04:06 · 492 阅读 · 0 评论 -
【leetcode with java】2 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原创 2015-04-13 14:32:49 · 453 阅读 · 0 评论 -
【leetcode with java】5 Longest Palindromic Substring
【分析】该问题的最优解可以从局部的最优解导出,且计算过程中存在大量重复计算,显然是要用动态规划了。用二维布尔数组mem[][]记录每个子串是否为回文,mem[i][j]表示第i个字符到第j个字符间的子串是否为回文。初始化:当i>=j时mem[i][j] =true, i=j时就一个字符必定为回文,ii+1的情况一样处理。过程:若S[i] == S[j]则mem[i][j] = me原创 2015-04-17 21:31:54 · 485 阅读 · 0 评论 -
【leetcode with java】4 Median of Two Sorted Arrays
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)).Tags: Divide and Conquer, A原创 2015-04-22 16:32:33 · 448 阅读 · 0 评论 -
【leetcode with java】0 序
前段时间做了一些leetcode。现在有个想法:用java做leetcode并坚持下去。于是开此专题,以便记录、分享和讨论。原创 2015-04-11 14:51:52 · 501 阅读 · 0 评论