
剑指offer
剑指offer题解
北半球的年少时光
这个作者很懒,什么都没留下…
展开
-
60 n个骰子的点数
package sort;import java.util.Arrays;public class Test60 { public static void main(String[] args) { solution(4); } public static void solution(int n) { int sum = 0; int[] s = new int[n * 6 + 1]; solution(s, ...原创 2020-05-09 07:51:09 · 214 阅读 · 0 评论 -
59_2队列的最大值
package sort;import java.util.Deque;import java.util.LinkedList;public class Test59_2 { class inter { int value; int index; public inter(int value, int index) { // TODO Auto-generated constructor stub ...原创 2020-05-09 07:50:04 · 158 阅读 · 0 评论 -
59滑动窗口的最大值
package sort;import java.util.*;public class Test59 { public static void main(String[] args) { System.out.println(maxInWindows(new int[] { 2, 3, 4, 2, 6, 2, 5, 1 }, 3)); } public static ArrayList<Integer> maxInWindows(int[] n...原创 2020-05-09 07:49:07 · 168 阅读 · 0 评论 -
58 反转字符串
package sort;import java.util.Stack;public class Test58 { public static void main(String[] args) { System.out.println(ReverseSentence2("student. a am I")); } private static String ReverseSentence3(String string) { // TODO A...原创 2020-05-09 07:47:03 · 171 阅读 · 0 评论 -
57_2 和为s的连续正整数序列
package sort;import java.util.ArrayList;public class Test57_2 { public static void main(String[] args) { System.out.println(FindContinuousSequence(15)); } public static ArrayList<ArrayList<Integer>> FindContinuousSeque...原创 2020-05-09 07:45:43 · 164 阅读 · 0 评论 -
Test57 和为s的数字
package sort;public class Test57 { public static void main(String[] args) { printnumber(new int[]{1,2,3,4,5,6,7,8,9,10},10 ); } public static void printnumber(int[] s, int targe)...原创 2020-04-08 08:57:33 · 214 阅读 · 0 评论 -
56_2 数组中唯一出现一次的数字
package sort;import java.util.Arrays;public class Test56_2 { public static void main(String[] args) { int[]e={3,3,3,4}; System.out.println(getn(e)); } public static...原创 2020-04-07 17:56:09 · 115 阅读 · 0 评论 -
56 数组中数字出现的次数
package sort;import javax.jws.Oneway;public class Test56 { public static void main(String[] args) { int[] s = { 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7 }; findSingle(s); } ...原创 2020-04-07 17:16:05 · 212 阅读 · 1 评论 -
55_2 判断平衡二叉树
package sort;public class Test55_2 { public static boolean isBalance(BinayTreeNode bt) { if (bt == null) return true; if (Math.abs(getdeepth(bt.left) - getdeepth(bt...原创 2020-04-07 17:10:03 · 112 阅读 · 0 评论 -
55二叉树的深度
package sort;public class Test55 { public static void main(String[] args) { int deepth = 1; BinayTreeNode root = new BinayTreeNode(1, null, null); makeTree(root, deepth)...原创 2020-04-07 17:06:33 · 117 阅读 · 0 评论 -
54 二叉搜索树中的第K大节点
package sort;public class Test54 { static int order = 0; public static void main(String[] args) { int deepth = 3; BinayTreeNode root = new BinayTreeNode(1, null, null); ...原创 2020-04-07 17:04:11 · 102 阅读 · 0 评论 -
53 1-n中缺失的数字
package sort;public class Test53_2 { public static void main(String[] args) { int[]a={0,1,2,3,5,6,7}; System.out.println(getFirstDisorder2(a)); } public st...原创 2020-04-07 17:00:29 · 175 阅读 · 0 评论 -
53 在排序数组中查找数字
package sort;public class Test53 { public static void main(String[] args) { int[] s = { 1, 2, 3, 3, 3, 3, 3, 4, 5, 6 }; System.out.println(getLast(s, 3, 0, s.length - ...原创 2020-04-06 10:16:04 · 129 阅读 · 0 评论 -
52 两个链表中的第一个公共节点
package sort;import java.util.Stack;public class Test52 { public static void main(String[] args) { ListNode a = new ListNode(1); ListNode b = new ListNode(2); ListNode...原创 2020-04-06 10:11:46 · 105 阅读 · 0 评论 -
51 数组中的逆序数对
package sort;import java.util.Arrays;public class Test51 { static int count = 0; public static void main(String[] args) { int[] s = new int[] { 1, 2, 3, 9, 8, 2, 0 }; coun...原创 2020-04-06 10:03:04 · 99 阅读 · 0 评论 -
50_2 删除字符串中重复出现的字符
package sort;import java.util.LinkedHashSet;public class Test50_3 { public static void main(String[] args) { System.out.println(depect("google")); } public static Strin...原创 2020-04-06 09:35:25 · 114 阅读 · 0 评论 -
50_1 从第一个字符串中删除第二个字符串出现过的字符
package sort;import java.util.HashSet;public class Test50_2 { public static void main(String[] args) { System.out.println(deepect("We are student", "aeiou")); } public static ...原创 2020-04-06 09:33:17 · 152 阅读 · 0 评论 -
50 第一次出现的字符串
package sort;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.Map;public class Test50 { public static void main(String[] args) { S...原创 2020-04-06 09:14:10 · 116 阅读 · 0 评论 -
49 丑数
package sort;public class Test49 { public static void main(String[] args) { System.out.println(uglynumber(1500)); } public static int uglynumber(int n) { if (n < 6) ...原创 2020-04-06 08:48:25 · 92 阅读 · 0 评论 -
48 最长不含重复的子字符串
package sort;public class Test48 { public static void main(String[] args) { System.out.println(getlongest("arabcacfr")); } public static int getlongest(String str) { int...原创 2020-04-06 08:30:49 · 168 阅读 · 0 评论 -
47 礼物的最大价值
package sort;import java.util.ArrayList;public class Test47 { static int max = 0; public static void main(String[] args) { int[][] ss = { { 1, 10, 3, 8 }, { 12, 2, 9, 6 }, { 5, 7,...原创 2020-04-06 08:19:10 · 130 阅读 · 0 评论 -
46 把数字翻译成字符串
package sort;import java.util.ArrayList;public class Test46 { static int count = 0; public static void main(String[] args) { System.out.println(countString(12258)); } pu...原创 2020-04-06 07:59:34 · 138 阅读 · 0 评论 -
45 把数组排列成最小数
package sort;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;public class Test45 { public static void main(String[] args) { String[] str = { "21"...原创 2020-04-04 12:49:33 · 97 阅读 · 0 评论 -
44 数字系列中某一为的数字
package sort;public class Test44 { public static void main(String[] args) { System.out.println(getn(190)); } public static int getn(int n) { if (n <= 10) ...原创 2020-04-04 12:45:46 · 116 阅读 · 0 评论 -
43 1-n整数中出现1 的次数
package sort;public class Test43 { public static void main(String[] args) { System.out.println(findones(451)); //解析 https://blog.youkuaiyun.com/ds19980228/article/details/82748063...原创 2020-04-04 12:26:02 · 127 阅读 · 0 评论 -
42 连续子数组的最大和
package sort;public class Test42 { public static void main(String[] args) { int[]test={1,-2,3,10,-4,7,2,-5}; System.out.println(getMax(test)); } public static int getMax(...原创 2020-04-04 09:01:06 · 94 阅读 · 0 评论 -
41 数据流中的中位数
package sort;import java.util.Comparator;import java.util.PriorityQueue;public class Test41 { public static void main(String[] args) { int[] s = { 1, 2 }; System.out.println(...原创 2020-04-04 08:49:34 · 187 阅读 · 0 评论 -
40 最小的K个数
package sort;import java.util.Comparator;import java.util.PriorityQueue;public class Test40 { public static void main(String[] args) { int[] a = { 4, 5, 1, 6, 2, 7, 3, 8 }; in...原创 2020-04-04 08:23:18 · 75 阅读 · 0 评论 -
39 数组中出现次数超过一半的数字
package sort;public class Test39 { public static void main(String[] args) { int[]s={1,1,1,1,1,1,1,1,2,3,2,2,2,5,4,2}; System.out.println(findMoreThanHalf(s)); } ...原创 2020-04-04 07:55:34 · 74 阅读 · 0 评论 -
38_4 八皇后问题
package sort;import java.util.Arrays;public class Test38_4 { public static void main(String[] args) { PL(new int[] {0,1,2,3,4}); } public static void PL(int[] a) { PL...原创 2020-04-04 07:50:49 · 127 阅读 · 0 评论 -
38_3 把8个数放在正方体的8个顶点上
package sort;import java.util.Arrays;public class Test38_3 { public static void main(String[] args) { PL("ABCEFGHI"); } public static void PL(String str) { char[] ch =...原创 2020-04-04 07:47:39 · 371 阅读 · 0 评论 -
38_2 字符串的组合
package sort;import java.util.ArrayList;public class Test38_2 { public static void main(String[] args) { Combain("ABC"); } public static void Combain(String str) { ch...原创 2020-04-04 07:44:06 · 107 阅读 · 0 评论 -
37_2 反序列化二叉树
package sort;public class Test37_2 { public static int index = 0; public static void main(String[] args) { String test = "124$$$35$$6$$"; Test37.printTree(DisSerialied(test)...原创 2020-04-03 17:06:21 · 101 阅读 · 0 评论 -
37 序列化二叉树
package sort;public class Test37 { public static void main(String[] args) { int deepth = 2; // int rootvalue=1; BinayTreeNode root = new BinayTreeNode(1, null, null); ...原创 2020-04-03 16:53:24 · 67 阅读 · 0 评论 -
36 二叉树和双向链表
package sort;public class Test36 { public static BinayTreeNode head = null; public static BinayTreeNode prehead = null; public static void main(String[] args) { int deepth = 2;...原创 2020-04-03 16:49:30 · 102 阅读 · 0 评论 -
35 复杂链表的复制
package sort;class ComliexListNode{ int value; ComliexListNode next; ComliexListNode sibling; public int getValue() { return value; } public void setValue(int va...原创 2020-04-03 16:43:31 · 125 阅读 · 0 评论 -
34 二叉树中和为某一值的路径
package sort;import java.util.ArrayList;import java.util.Currency;public class Test34 { public static void main(String[] args) { int deepth = 2; // int rootvalue=1; Bi...原创 2020-04-03 16:27:45 · 123 阅读 · 0 评论 -
33_3 之字形打印二叉树
package sort;import java.util.Stack;public class Test32_3 { public static void main(String[] args) { int deepth = 3; // int rootvalue=1; BinayTreeNode root = new Binay...原创 2020-04-03 16:13:31 · 73 阅读 · 0 评论 -
32 从上到下打印二叉树
package sort;import java.util.LinkedList;import java.util.Queue;public class Test32 { public static Queue<BinayTreeNode> qu = new LinkedList<BinayTreeNode>(); public static v...原创 2020-04-03 15:59:48 · 109 阅读 · 0 评论 -
31 栈的压入,弹出序列
package sort;import java.util.Stack;public class Test31 { public static void main(String[] args) { System.out.println(function("1", "2")); } public static boolean function(St...原创 2020-04-03 11:47:43 · 68 阅读 · 0 评论