数据结构
文章平均质量分 68
wwzheng16
这个作者很懒,什么都没留下…
展开
-
切割钢丝,最短为1cm ,任意三段不能构成三角形
import java.util.ArrayList;public class Main { /* * 总共144cm,切割成N段,最短1cm,其中任意三段都不能构成三角形,问N的最大值以及每一段的长度 * 实现过程: * 按照斐波那契的数列进行截取,截取的长度和<=144 */ public static void main(S...原创 2018-08-24 21:25:32 · 420 阅读 · 0 评论 -
计算出第一个文本中包含第二个文本每个单词的最短文本
import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Map.Entry;import java.util.Set;import org.junit.Test;public class solution { @Test public void testF...原创 2018-07-14 08:06:16 · 283 阅读 · 0 评论 -
快速排序
import org.junit.Test;public class solution { @Test public void test2() { int[] arr={3,2,1}; quickSort(arr, 0, arr.length-1); for(int ele:arr){ System.ou...原创 2018-07-20 09:38:39 · 196 阅读 · 0 评论 -
反转int型数据
import org.junit.Test;public class solution { @Test public void testFunc(){ int res = reverseInt(123); System.out.println("res: "+res); }// 反转int型数据 public int reverseInt(...原创 2018-07-13 00:07:50 · 947 阅读 · 0 评论 -
字符串的逆序--手写
import org.junit.Test;public class solution { @Test public void testFunc(){ String string = "hello"; String reString = reverseString(string); System.out.println("res: "+reSt...原创 2018-07-12 23:15:56 · 1332 阅读 · 0 评论 -
判断一棵树是否为BST----使用递归方法
import org.junit.Test;public class solution { @Test public void testFunc(){ } public boolean isBST(TreeNode root){ return isBST2(root, Integer.MIN_VALUE, Integer...原创 2018-07-12 22:52:20 · 637 阅读 · 0 评论 -
字符串转int类型
import org.junit.Test;public class solution { @Test public void testFunc(){// String string = "-10"; String string = "10"; int res = parseInt(string); System.out.println("res: "+res)...原创 2018-07-12 21:12:25 · 9036 阅读 · 0 评论 -
求两个数的最大公约数
import org.junit.Test;public class solution { @Test public void testFunc(){ int maxYueShu = maxYueShu(12, 8); System.out.println("res: "+maxYueShu); } public ...原创 2018-07-12 20:47:21 · 176 阅读 · 0 评论 -
送货路线
import java.util.ArrayList;import java.util.Scanner;import org.junit.Test;public class solution { @Test public void test2(){ Scanner scanner = new Scanner(System.in); S...原创 2018-07-18 18:33:00 · 475 阅读 · 0 评论 -
把某种格式的字符串转化为驼峰字符串
import org.junit.Test;public class solution { @Test public void testFunc(){ String string = " border-left-color"; String res = hump(string); System.out.println("res: "+res)...原创 2018-07-12 17:44:28 · 752 阅读 · 0 评论 -
中序遍历下某个元素的下一个节点---考察中序遍历的非递归实现
import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Map.Entry;import java.util.Set;import java.util.Stack;import org.junit.Test;public class solution { @Te...原创 2018-07-14 09:57:56 · 171 阅读 · 0 评论 -
把数字翻译成字符串---记忆化存储
import java.util.Arrays;import java.util.Comparator;import org.junit.Test;public class solution { @Test public void testFunc(){ int res = search(22); System.out.println("res: "+res...原创 2018-07-16 08:30:30 · 245 阅读 · 0 评论 -
把数字翻译成字符串
import java.util.Arrays;import java.util.Comparator;import org.junit.Test;public class solution { @Test public void testFunc(){ int res = searchNum("12258", 0); System.out.println(...原创 2018-07-16 08:15:55 · 435 阅读 · 0 评论 -
把数组排成最小的数
import java.util.Arrays;import java.util.Comparator;import org.junit.Test;public class solution { @Test public void testFunc(){ int[] arr = {3,32,321}; String minNum = minNum(arr);...原创 2018-07-16 07:39:49 · 98 阅读 · 0 评论 -
归并排序
import org.junit.Test;public class solution { @Test public void test2() { int[] arr={9,8,7,6,5,4,3,2,1}; mergeSort(arr, 0, arr.length-1); for(int ele:arr){ ...原创 2018-07-20 20:44:13 · 201 阅读 · 0 评论 -
数字序列中某一位的数字
import org.junit.Test;public class solution { @Test public void testFunc(){ char res = locationNum(13); System.out.println("res: "+res); } //数字序列中的某一位数字 pu...原创 2018-07-15 13:50:42 · 309 阅读 · 0 评论 -
连续子数组的最大和
import org.junit.Test;public class solution { @Test public void testFunc(){ int[] arr={1,-2,3,10,-4,7,2,-5}; int res=maxSubArr(arr); System.out.println("res: "+res); ...原创 2018-07-15 09:40:40 · 107 阅读 · 0 评论 -
判断二叉树B是不是二叉树A的子结构
import org.junit.Test;public class solution { @Test public void testFunc(){ TreeNode root1 = new TreeNode(1); TreeNode root2 = new TreeNode(2); TreeNode root3 = new TreeNode...原创 2018-07-14 21:42:33 · 236 阅读 · 0 评论 -
打印从1到n的最大n位数---全排列---大数问题
import java.io.PrintStream;import org.junit.Test;public class solution { @Test public void testFunc(){ printN(2); } @Test public void test2(){ printNum("01"); ...原创 2018-07-14 18:30:08 · 486 阅读 · 0 评论 -
把26进制的字母转成10进制
import org.junit.Test;public class solution { @Test public void testFunc(){ String string="AA"; int res = transbase10(string); System.out.println("res: "+res); ...原创 2018-07-14 15:13:14 · 4104 阅读 · 0 评论 -
判断矩阵中是否存在某个字符串路径
import org.junit.Test;public class solution { @Test public void testFunc(){ char[][] matrix = { {'a','b','t','g'}, {'c','f','c','s'}, {'j','d'...原创 2018-07-14 14:18:04 · 431 阅读 · 0 评论 -
青蛙跳台的递归实现
import org.junit.Test;public class solution { @Test public void testFunc() throws Exception{ int res = jumpStar(5); System.out.println("res: "+res); } private int...原创 2018-07-12 16:42:49 · 288 阅读 · 0 评论 -
小朋友发糖果,相邻小朋友高分比低分的糖果多,最少需要多少糖果
import java.awt.Adjustable;import java.util.Stack;import org.junit.Test;public class Test1 { @Test public void testFunc() { int[] arr = {2,4,5,2,3}; int res = minNum(arr)...原创 2018-07-18 17:02:52 · 971 阅读 · 0 评论 -
求n以内的最大质数
package codePra;import org.junit.Test;//求n以内的最大质数public class helloword { @Test public void testFunc(){ int res = maxPrime(10); System.out.println("res: "+res); } /* * 使用...原创 2018-07-09 23:36:41 · 3263 阅读 · 0 评论 -
单例模式之懒汉式
//单例模式之懒汉式public class Singleton { private Singleton() { // TODO Auto-generated constructor stub } private static Singleton instance; public static synchronized Singleton getInstanc...原创 2018-07-09 22:36:10 · 86 阅读 · 0 评论 -
单例模式之饿汉式
//单例模式之饿汉式public class Singleton { private Singleton() { // TODO Auto-generated constructor stub } private static Singleton instance = new Singleton(); public static Singleton getIn...原创 2018-07-09 22:32:49 · 80 阅读 · 0 评论 -
两个字符串的最长公共子序列
import org.junit.Test;public class solution { @Test public void testFunc(){ String s1 = "ABCD"; String s2 = "AEBD"; int res = minDistance(s1, s2); System.out.prin...原创 2018-07-09 22:27:08 · 157 阅读 · 0 评论 -
在N个元素中选取前M个元素
import org.junit.Test;public class solution { @Test public void testFunc(){// int[] arr = {5,4,3,2,1}; int[] arr = {1,2,3,4,5,6}; maxArr(arr,3); for(int i=0;i<...原创 2018-07-09 20:40:44 · 582 阅读 · 0 评论 -
堆排序
import org.junit.Test;public class solution { @Test public void testFunc(){ int[] arr = {5,4,3,2,1}; maxHeap(arr); for(int ele:arr){ System.out.print(ele+" "...原创 2018-07-09 19:01:20 · 101 阅读 · 0 评论 -
冒泡排序
import org.junit.Test;public class solution { /* * 先进行一趟排序 * 在进行多趟 * */ @Test public void testFunc(){ int[] arr = {5,3,7,8,3,2,1}; bubbleSort(arr); for(in...原创 2018-07-09 14:59:53 · 96 阅读 · 0 评论 -
快速排序-优化算法
public class Solution2 { @Test public void testFunction() { int[] arr = {3,2,1}; quickSort(arr); for(int x:arr){ System.out.print(x+" "); } } /*...原创 2018-05-23 11:23:48 · 134 阅读 · 0 评论 -
合并排序优化算法
public class Solution { @Test public void testFunction() { int[] arr = {9,8,7,6,5,4,3,2,1}; mergeSort(arr); for (int x : arr) { System.out.print(x + " "); ...原创 2018-05-22 22:51:20 · 489 阅读 · 0 评论 -
插入排序
public class Solution2 { @Test public void testFunction() { int[] arr = {9,8,7,6,5,4,3,2,1}; insertSort(arr); for(int x:arr){ System.out.print(x+" "); } ...原创 2018-05-22 13:04:00 · 91 阅读 · 0 评论 -
判断一棵树是不是平衡二叉树
import org.junit.Test;public class solution { @Test public void testFunc(){ TreeNode root1 = new TreeNode(1); TreeNode root2 = new TreeNode(2); TreeNode root3 = new TreeNode(3); Tree...原创 2018-07-16 15:20:53 · 351 阅读 · 0 评论 -
数组中除两个数只出现1次外,其他数字均出现两次
import org.junit.Test;public class solution { @Test public void testFunc(){ int[] arr= {2,4,3,6,3,2,5,5}; int[] searchNum = searchNum(arr); System.out.println("num...原创 2018-07-16 16:18:37 · 284 阅读 · 0 评论 -
后序遍历的非递归实现---利用栈
//后续遍历的非递归实现 public void postOrder(TreeNode root){ Stack<TreeNode> stack = new Stack<TreeNode>(); TreeNode p = root; stack.push(p); TreeNode pre = null; ...原创 2018-07-12 16:10:44 · 2284 阅读 · 0 评论 -
中叙遍历的非递归实现---利用栈
//中叙遍历的非递归实现---利用栈 public void inOrder(TreeNode root){ Stack<TreeNode> stack = new Stack<TreeNode>(); TreeNode p = root; while (p!=null || !stack.isEmpty()) { ...原创 2018-07-12 14:28:08 · 101 阅读 · 0 评论 -
前序遍历的非递归实现--利用栈
import java.io.BufferedReader;import java.io.FileReader;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.Map;import java.ut...原创 2018-07-12 14:14:59 · 550 阅读 · 0 评论 -
一个文件,其中内容以换行与空格作为每个单词的分隔,手写代码,将单词按单词的出现次数排序
import java.io.BufferedReader;import java.io.FileReader;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.Map;import java.ut...原创 2018-07-11 16:37:17 · 721 阅读 · 1 评论 -
求一个数组每个元素右边第一个比它大的元素/单调栈
import java.util.Stack;import org.junit.Test;public class solution { @Test public void testFunc(){ int[] arr = {13,7,6,12}; int[] res = get(arr); for(int ele:res){ ...原创 2018-07-11 14:05:59 · 1971 阅读 · 0 评论