0%

Description

Given a 32-bit signed integer, reverse digits of an integer.

Example 1:

1
2
Input: 123
Output: 321

Example 2:

1
2
Input: -123
Output: -321

Example 3:

1
2
Input: 120
Output: 21

Noted:

Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1].
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

Difficulty: Easy

Code:

1
2
3
4
5
class Solution {
public int reverse(int x) {

}
}

题意

给定一个32位有符号的整数,找出其反转后的整数。反转后的数字如果溢出,则返回0。

阅读全文 »

自定义页面的问题

只有source目录下的文件才会发布到public(能够在网络上访问到),因此Hexo只默认渲染source目录下的文件,但有一些前端作品或demo页我们不希望经过渲染,而是能保持完全自定义的样子,那该怎么用Hexo添加自定义的web页面呢?

第一种解决方法

第一种方法是使用Hexo提供的跳过渲染配置,针对某个文件或者目录进行排除。具体步骤,打开博客根目录_config.yml,找到其中skip_render项,这个项目用来配置/source/中需要跳过渲染的文件或目录。

阅读全文 »

Description

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)

1
2
3
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 take a string and make this conversion given a number of rows:

1
string convert(string s, int numRows);

Example 1:

1
2
Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"

Example 2:

1
2
3
4
5
6
7
8
Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:

P I N
A L S I G
Y A H R
P I

Difficulty: Medium

Code:

1
2
3
4
5
class Solution {
public String convert(String s, int numRows) {

}
}

题意

某字符串是基于给定的行数使用锯齿状格式书写,然后逐行读取成字符串。写一段代码完成该转换。

阅读全文 »

Description

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

1
2
3
Input: "babad"
Output: "bab"
Note: "aba" is also a valid answer.

Example 2:

1
2
Input: "cbbd"
Output: "bb"

Difficulty: Medium

Code:

1
2
3
4
5
class Solution {
public String longestPalindrome(String s) {

}
}

题意

给定一个字符串,找出最长的回文子串,假定字符串最大长度是1000。

阅读全文 »

Description

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)).

You may assume nums1 and nums2 cannot be both empty.

Example 1:

1
2
3
4
nums1 = [1, 3]
nums2 = [2]

The median is 2.0

Example 2:

1
2
3
4
nums1 = [1, 2]
nums2 = [3, 4]

The median is (2 + 3)/2 = 2.5

Difficulty: Hard

Code:

1
2
3
4
5
class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {

}
}

题意

给定两个有序数组,长度分别是m和n。找出这两个数组到中位数,总体到时间复杂度要求O(log (m+n)),假定两个数组都不为空。

阅读全文 »