Leetcode
文章平均质量分 79
sewssb001
这个作者很懒,什么都没留下…
展开
-
ZigZag Conversion
public class Solution { public String convert(String s, int nRows) { int len = s.length(); if (len == 0 || nRows <= 1) return s; String[] ans = new String[nR原创 2015-05-09 11:52:14 · 269 阅读 · 0 评论 -
Integer to Roman
public class Solution { public String intToRoman(int num) { String[][] c= new String[][]{{"0","I","II","III","IV","V","VI","VII","VIII","IX"},{"0","X","XX","XXX","XL","L","LX"原创 2015-05-24 14:23:07 · 266 阅读 · 0 评论 -
Longest Common Prefix
public class Solution { public String longestCommonPrefix(String[] strs) { if (strs == null) return ""; if (strs.length == 0) return ""; String prefix = strs[0]; if原创 2015-05-24 14:21:58 · 268 阅读 · 0 评论 -
Pascal's Triangle
public class Solution { public List> generate(int numRows) { List> ans = new ArrayList>(); for (int i=0; i<numRows; i++){ List v = new ArrayList(); for (i原创 2015-06-08 21:57:50 · 214 阅读 · 0 评论 -
Container With Most Water
public class Solution { public int maxArea(int[] height) { int max = 0; int left = 0; int right = height.length-1; while (left<right){ max = Math.max(ma原创 2015-05-19 22:33:00 · 220 阅读 · 0 评论 -
Regular Expression Matching
// 用c/c++代码会简洁并且效率高很多。直接使用c/c++中的字符数组char*做代码会简洁很多 package leetcode.xuyi; import org.junit.Test; /** * Created by ethan on 2015/5/17. */ public class RegularExpressionMatching { public boole原创 2015-05-17 23:05:39 · 247 阅读 · 0 评论 -
Remove Nth Node From End of List
public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if (head == null || n==0) return null; ListNode listNode = new ListNode(0); listNode.next原创 2015-05-26 23:30:30 · 231 阅读 · 0 评论 -
Two Sum
package leetcode.xuyi; import org.junit.*; import java.util.Arrays; import java.util.HashMap; /** * Created by ethan on 2015/5/2. */ public class No1TwoSum { // 思路1 // 直接双重循环必然超时 // 时间原创 2015-05-02 10:27:21 · 294 阅读 · 0 评论 -
Palindrome Number
package leetcode.xuyi; import org.junit.Test; /** * Created by ethan on 2015/5/13. */ public class PalindromeNumber { public boolean isPalindrome(int x) { if(x<0) return f原创 2015-05-13 23:01:40 · 213 阅读 · 0 评论 -
Median of Two Sorted Arrays
package leetcode.xuyi; import org.junit.Test; /** * Created by ethan on 2015/5/4. */ public class MedianOfTwoSortedArrays { // 思路1: 由于时间复杂度限制在O(log(m+n)),只能使用二分法 // 其实这道题可以一般化到求最小的第n位数原创 2015-05-04 21:32:51 · 284 阅读 · 0 评论 -
Median of Two Sorted Arrays
package leetcode.xuyi; import org.junit.Test; /** * Created by ethan on 2015/5/4. */ public class MedianOfTwoSortedArrays { // 思路1: 由于时间复杂度限制在O(log(m+n)),只能使用二分法 // 其实这道题可以一般化到求最小的第n位数原创 2015-05-04 21:32:18 · 245 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
package leetcode.xuyi; import org.junit.Test; /** * Created by ethan on 2015/5/4. */ public class LongestSubstringWithoutRepeatingCharacters { // 记下字串的起始位置,当遇到substring中有的字符的时候,起始位置+1 //原创 2015-05-04 18:24:40 · 240 阅读 · 0 评论 -
Add Two Nums
package leetcode.xuyi; import org.junit.*; /** * Created by ethan on 2015/5/3. */ public class AddTwoNums { // 参考别人代码之后发现 // while (l1 != NULL || l2 != NULL) 这样的思路貌似代码更加简洁了 // 我这种解法代码重原创 2015-05-03 22:16:46 · 281 阅读 · 0 评论 -
Reverse Integer
package leetcode.xuyi; import org.junit.Test; /** * Created by ethan on 2015/5/9. */ public class ReverseInteger { public int reverse(int x) { if(x==-2147483648 || x==2147483647)原创 2015-05-09 23:44:47 · 223 阅读 · 0 评论 -
Longest Palindromic Substring
package leetcode.xuyi; import org.junit.Test; /** * Created by ethan on 2015/5/7. */ public class LongestPalindromicSubstring { @Test public void test5(){ System.out.println(long原创 2015-05-07 22:38:10 · 233 阅读 · 0 评论 -
Generate Paratheses
public class Solution { public List generateParenthesis(int n) { List arrayList = new ArrayList(); generate(arrayList, "", 0, 0, n); return arrayList; } public void转载 2015-06-15 22:59:14 · 294 阅读 · 0 评论