LeetCode
luxiaobing2016
这个作者很懒,什么都没留下…
展开
-
Reverse Integer
比较简单public class Solution { public static int reverse(int x) { long flag = 0; while (x != 0) { flag = flag * 10 + x % 10; x = x / 10; } while (Math.abs(flag) > 2147483647) return 0原创 2015-08-08 18:59:49 · 262 阅读 · 0 评论 -
最长回文子序列的java解法
方法一:中心法(非常简单,易于理解) public class Solution { public String longestPalindrome(String s) { char[] ch = s.toCharArray(); String str = " "; String re = ""; if(s.length()==0) return null原创 2015-08-02 17:50:02 · 803 阅读 · 0 评论 -
Median Of Two Sorted Array的寻找k 的解法
public class SolutionBySearchK { public double findMedianSortedArrays(int A[], int B[]) { int lena = A.length; int lenb = B.length; int len = lena + lenb; if (len % 2 == 0) { return (findM转载 2015-08-01 19:47:53 · 274 阅读 · 0 评论 -
3Sum
【题目】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】1.Elements in a triplet原创 2015-08-13 15:53:01 · 289 阅读 · 0 评论 -
Roman to Integer
如果当前字符小于前个字符对应的数字加上当前字符对应的数字减去前一个数字的两倍 否则直接加上当前数字就好public class Solutiion { public static int romanToInt(String s) { char[] symbol = { 'I', 'V', 'X', 'L', 'C', 'D', 'M' };原创 2015-08-12 11:25:00 · 227 阅读 · 0 评论 -
Longest Common Pefix
【题目】Write a function to find the longest common prefix string amongst an array of strings.【代码】public class Solution { public static String longestCommonPrefix(String[] strs) { int tem原创 2015-08-12 15:41:14 · 278 阅读 · 0 评论 -
Integer to Roman
【题目】Given a roman numeral, convert it to an integer. Or, Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.【罗马数字】1~9: {"I", "I原创 2015-08-11 18:15:22 · 265 阅读 · 0 评论 -
Container with most water
题目比较简单,每次找较小的板往里移,得到的容器的容积最大的就是所求的容积public class Solution { public static int maxArea(int[] height) { int begin = 0, high, end = height.length - 1; int max = 0; while (en原创 2015-08-11 17:14:37 · 268 阅读 · 0 评论 -
Regular Expresssion Matching
class Solution {public: bool isMatch(const char *s, const char *p) { int i, j; int m = strlen(s); int n = strlen(p); /** * b[i + 1][j + 1]: if s[0..i] ma转载 2015-08-11 15:30:17 · 231 阅读 · 0 评论 -
3Sum Closet
【题目】Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have e原创 2015-08-25 11:18:34 · 412 阅读 · 0 评论 -
Palindrome Number
题目比较简单,一次AC注意这个回文数可以通过比较反转后的数字和原数字比较是否相等,如果相等,就返回true,而最长回文子序列的那个则不可以public class Solution { public static boolean isPalindrome(int x) { if (x < 0) return false; int temp = x; int flag原创 2015-08-08 23:56:19 · 267 阅读 · 0 评论 -
回文数zigzag
public class Solution { String convert(String s, int nRows) { int i = 0, j = 0; String result = ""; String[] strlist = new String[nRows]; for (i = 0; i < nRows; i++) { strlist[i] = "";原创 2015-08-06 23:28:55 · 304 阅读 · 0 评论