随笔分类 -  jz

摘要:####反转链表public static void fanlian(Node node){ Node pre =null; Node next =null; while (node!=null){ next = node.getNext(); node.setNext(pre); pre=node 阅读全文
posted @ 2021-05-24 11:10 菜鸟哟 阅读(57) 评论(0) 推荐(0)
摘要:#####获得链表倒数第k个结点public static Node getK(Node node,int k){ List<Node> list = new ArrayList(); while (node!=null){ list.add(node); node=node.getNext(); 阅读全文
posted @ 2021-05-24 11:02 菜鸟哟 阅读(72) 评论(0) 推荐(0)
摘要:#####输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变public static void test4(){ int[]arry ={1,2,3,4,5}; int j=0; i 阅读全文
posted @ 2021-05-24 10:47 菜鸟哟 阅读(57) 评论(0) 推荐(0)
摘要:####二进制中一的个数public static int test3(int n){ int count =0; while (n!=0){ n=n&n-1; count++; } return count;} 阅读全文
posted @ 2021-05-24 10:14 菜鸟哟 阅读(75) 评论(0) 推荐(0)
摘要:#####青蛙一次可以跳1,2,3***,n个台阶,问有多少种跳法public static int test1(int n){ int res=0; if (n<=3){ for (int i=0;i<=n;i++){ res+=i; } return res; } res=6; int i=3; 阅读全文
posted @ 2021-05-24 10:02 菜鸟哟 阅读(67) 评论(0) 推荐(0)
摘要://一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。分析:最后一次跳1有f(n-1)跳法,最后一跳2有f(n-2)跳法,f(n)=f(n-1)+f(n-2)public class test { public static void main(String[ 阅读全文
posted @ 2021-05-24 09:51 菜鸟哟 阅读(115) 评论(0) 推荐(0)
摘要:####用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 ####pop返回栈顶元素 empty判断栈是否为空 import java.util.Stack; public class Solution { Stack<Integer> stack1 = new 阅读全文
posted @ 2021-05-24 07:11 菜鸟哟 阅读(52) 评论(0) 推荐(0)
摘要:####大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,第1项是1)。 n≤39n≤39 public class Solution { public int Fibonacci(int n) { if(n==0){ return 0; }else 阅读全文
posted @ 2021-05-24 07:03 菜鸟哟 阅读(56) 评论(0) 推荐(0)
摘要:###把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。 import java.util.ArrayList;public class Solution { pu 阅读全文
posted @ 2021-05-24 06:59 菜鸟哟 阅读(73) 评论(0) 推荐(0)
摘要:###输入一个链表,按链表从尾到头的顺序返回一个ArrayList。 public class Solution { public ArrayList<Integer> printListFromTailToHead(ListNode listNode) { ArrayList arry = new 阅读全文
posted @ 2021-05-23 20:42 菜鸟哟 阅读(61) 评论(0) 推荐(0)
摘要:请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 public String replaceSpace (String s) { // write code here s = s.repla 阅读全文
posted @ 2021-05-23 20:29 菜鸟哟 阅读(52) 评论(0) 推荐(0)
摘要:多维有序数组寻找目标值 public class dwsz { public static void main(String[] args) { int [][]arry = {{1,2,3},{4,6,9},{10,12,16},{20,32,46}}; test01(66,arry); } pu 阅读全文
posted @ 2021-05-23 20:25 菜鸟哟 阅读(109) 评论(0) 推荐(0)