最重点,哈希表 `importjava.util.Scanner;importjava.util.;publicclassCf1300c{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);Hashtable<String,Integer>hash_t=newHashtable<>();intn=sc.nextInt();sc.nextLine();/这段代码是一个简单的哈希表应用,实现了一个功能:检查输入的字符串是否在哈希表中已经存在,如果存在,则输出该字符串的出现次数+1,如果不存在,...

  MpDIILUd3rHo   2023年11月01日   93   0   0 Java

2022蓝桥杯b组 A题 importjava.math.BigInteger; publicclassA{ publicstaticvoidmain(String[]args){ BigIntegerbigInteger=newBigInteger("20");//高精度 BigIntegera=newBigInteger("1"); for(inti=0;i<22;i){ a=a.multiply(bigInteger);//multiply是java中乘的意思 } BigIntegerc=newBigInteger("7"); a=a.remainder(c);//remai...

  MpDIILUd3rHo   2023年11月01日   35   0   0 Java

递归相关知识2 多路递归--斐波那契额数列 importjava.util.Arrays; //递归求斐波那契第n项 publicclassfeibonaqie{ publicstaticintfibonacci(intn){ int[]cache=newint[n+1]; Arrays.fill(cache,-1); cache[0]=0; cache[1]=1;//[0,1,-1,-1,-1,-1] returnf(n,cache); } publicstaticintf(intn,int[]cache){ /if(n0){ return0; } if(n1){ return1; }/...

  MpDIILUd3rHo   2023年11月01日   88   0   0 Java

/数据结构单向链表基本操作 节点类 / importjava.util.Iterator; importjava.util.function.Consumer; publicclassshujujiegouimplementsIterable<Integer>{//整体 privateNodehead;//头指针 @Override publicIterator<Integer>iterator(){ //匿名内部类->带名字的内部类 returnnewNodeIterator(); } privateclassNodeIteratorimplementsI...

  MpDIILUd3rHo   2023年11月01日   36   0   0 算法与数据结构

一.链表带哨兵 importjava.util.Iterator; importjava.util.function.Consumer; //带哨兵 publicclassshuju02implementsIterable<Integer>{//整体 privateNodehead=newNode(666,null);//头指针 ​@Override ​publicIterator<Integer>iterator(){ ​//匿名内部类->带名字的内部类 ​returnnewNodeIterator(); ​} ​privateclassNodeIterato...

  MpDIILUd3rHo   2023年11月01日   331   0   0 算法与数据结构

递归 递归小题练习 publicstaticintf(intn){ if(n1){ return1; } returnnf(n-1); } publicstaticvoidmain(String[]args){ intf=f(5); } 递归反向打印字符串-c的话,就正序,java正逆无所谓 publicstaticvoidf(intn,Stringstr){ if(nstr.length()){ return; } f(n+1,str); System.out.println(str.charAt(n)); } publicstaticvoidmain(String[]args){ f...

  MpDIILUd3rHo   2023年11月01日   75   0   0 算法与数据结构

反转链表-力扣206 方法一 publicListNodereverseList1(ListNodeo1){ ListNoden1=null; ListNodep=o1; while(p!=null){ n1=newListNode(p.val,n1);//插入的下一个指向新链表的头部 p=p.next; } returnn1; } 方法二 / 方法2写了两个类库,运用了面向和对象的思想,创建建立和移除两个方法 与方法1类似,构造一个新链表,从旧链表头部移除节点,添加到新链表头部,完成后 新链表即是倒序的,区别在于原题目未提供节点外层的容器类,这里提供一个,另外一 个区别是并不去构造新节点 ...

  MpDIILUd3rHo   2023年11月01日   44   0   0 算法与数据结构

判环算法01 检验链表是否有环 //判断环 publicbooleanhasCycle(ListNodehead){ ListNodep1=head;//乌龟 ListNodep2=head;//兔子 while(p2!=null&&p2.next!=null){ p1=p1.next; p2=p2.next.next; if(p1p2){ returntrue; } } returnfalse; } 思路:利用了快慢指针的原理,快的只要与慢的相遇,就代表终究是一个圆环 判断环的位置02 publicListNodehasCycle(ListNodehead){ List...

  MpDIILUd3rHo   2023年11月01日   108   0   0 算法与数据结构

回文比较 步骤1.找中间点 用到了查找链表中间节点-快慢指针法 publicListNodemiddleNode(ListNodehead){ ListNodep1=head; ListNodep2=head; while(p2!=null&&p2.next!=null){ p1=p1.next; p2=p2.next.next; } returnp1; } 步骤2.中间点后半个链表反转 利用插入排序链表 privateListNodereverse(ListNodeo1){ ListNoden1=null;//新链表开始为空 while(o1!=null){//如果没有到...

  MpDIILUd3rHo   2023年11月01日   95   0   0 算法与数据结构

合并有序数组 方法1-递归 //运用的思想就是比较谁大,谁就先被排进数组 publicstaticvoidmerge(int[]a1,inti,intiEnd,intj,intjEnd, int[]a2,intk){ //定义了一个a1数组,分了i,iEnd边界和j.jEnd边界,实际上是分成两个数组进行判断,比较判断哪个先进a2数组 if(i>iEnd){//如果超出进行数组迁移 System.arraycopy(a1,j,a2,k,jEnd-j+1); //原数组,开始迁移的位置,新数组,迁移到的位置,迁移的长度 return; } if(j>jEnd){ System.arr...

  MpDIILUd3rHo   2023年11月01日   102   0   0 算法与数据结构

01背包问题 publicclassKnapsackProblem{ publicstaticvoidmain(String[]args){ int[]w={1,2,3,4,5}; int[]value={3,4,6,8,10}; intcapacity=10; intn=w.length; ZeroOneKnapsack(w,value,n,capacity); } / @paramw重量 @paramvalue价值 @paramn种类 @paramcapacity容量 / publicstaticvoidZeroOneKnapsack(int[]w,int[]value,intn,i...

  MpDIILUd3rHo   2023年11月01日   64   0   0 算法与数据结构
关注 更多

空空如也 ~ ~

粉丝 更多

空空如也 ~ ~