標籤: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 NA P L S I I GY I RAnd then read line by line:
標籤:import java.text.*;public class StringAlign extends Format{public static final int JUST_LEFT=‘l‘; //靠左對齊常量public static final int JUST_RIGHT=‘r‘; //靠右對齊常量public static final int JUST_CENTER=‘c‘; //置中常量private int just; //當前的對其private int
標籤:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321解題思路:將數字翻轉並不難,可以轉成String類型翻轉,也可以逐位翻轉,本題涉及到的主要是邊界和溢出問題,使用Long或者BigInteger即可解決。題目不難:JAVA實現如下:public class Solution { static public int reverse(int x) {
標籤: 1 package sorting; 2 3 /** 4 * 堆排序 5 * 平均O(nlogn),最好O(nlogn),最壞O(nlogn);空間複雜度O(1);不穩定;較複雜 6 * @author zeng 7 * 8 */ 9 public class DuiPaixu {10 11 public static void duipaixu(int[] a) {12 int i, tmp;13 for (i = a.length
標籤: 1 package sorting; 2 3 /** 4 * 快速排序 5 * 平均O(nlogn),最好O(nlogn),最壞O(n^2);空間複雜度O(nlogn);不穩定;較複雜 6 * @author zeng 7 * 8 */ 9 public class Kuaisupaixu {10 11 public static int sort(int[] a, int i, int j) {12 int key = a[i];13