文章列表
Reverse Integer
- 博客分类:
- leetcode刷题
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.
这题挺简单的,我用了一个比较取巧的方式。效率不会太高。可以用普通的方式来做,那样效率会高很多。
public class Solution {
public int reverse(int x) {
int i = 0;
boolean b = x>0?true:false;
int temp = b?x:-x;
Str ...
ZigZag Conversion
- 博客分类:
- leetcode刷题
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 that will ...
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 S ...
Add Two Numbers
- 博客分类:
- leetcode刷题
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 -> 6 -> 4)
Output: 7 -> 0 -> 8
这题比较简单,就是一个大数据的加 ...
[size=24px;]Longest Substring Without Repeating Characters[/size]
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. ...
There are two sorted arrays A and B 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 findMedi ...
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 returned answers (both index1 and index2) are ...