`
hcx2013
  • 浏览: 88675 次
社区版块
存档分类
最新评论
文章列表

Integer to Roman

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.   public class Solution { public String intToRoman(int num) { Map<Integer, String> map = new HashMap<Integer, String>(); map.put(1, "I"); ...
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 input string (not partial). The function prototype should be: bool isMatch(const char *s, const char ...
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, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water ...
Determine whether an integer is a palindrome. Do this without extra space.   public class Solution { public boolean isPalindrome(int x) { if (x < 0) { return false; } int div = 1; while (x / div >= 10) { div *= 10; } ...
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 specified vaguely (ie, no given input specs). You ...

Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321   public class Solution { public int reverse(int x) { int num = 0; for (; x != 0; x/=10) { if (Math.abs(num) > Integer.MAX_VALUE/10) { return 0; } ...

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 N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR"   Write the code ...
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. 给定一个字符串,求出其最长回文子串。   public class Solution { public String longestPalindrome(String s) { if (s.length() == ...
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)).     public class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int len1 = nums1.len ...
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 length of 1. ...

Two Sum

https://leetcode.com/problems/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 index1 must be less than index2. Please note that your ...
题目:http://oj.leetcode.com/problems/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 -> ...
Global site tag (gtag.js) - Google Analytics