摘要: ####二进制中一的个数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 菜鸟哟 阅读(71) 评论(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 菜鸟哟 阅读(59) 评论(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 菜鸟哟 阅读(108) 评论(0) 推荐(0)
摘要: public static void quick_sort(int low,int high,int[]arry){ int i,j,jizhun,temp; if (low>high){ return; } i = low; j = high; jizhun = arry[low]; while 阅读全文
posted @ 2021-05-24 07:22 菜鸟哟 阅读(42) 评论(0) 推荐(0)
摘要: ####用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 ####pop返回栈顶元素 empty判断栈是否为空 import java.util.Stack; public class Solution { Stack<Integer> stack1 = new 阅读全文
posted @ 2021-05-24 07:11 菜鸟哟 阅读(42) 评论(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 菜鸟哟 阅读(46) 评论(0) 推荐(0)
摘要: ###把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。 import java.util.ArrayList;public class Solution { pu 阅读全文
posted @ 2021-05-24 06:59 菜鸟哟 阅读(60) 评论(0) 推荐(0)
摘要: ###输入一个链表,按链表从尾到头的顺序返回一个ArrayList。 public class Solution { public ArrayList<Integer> printListFromTailToHead(ListNode listNode) { ArrayList arry = new 阅读全文
posted @ 2021-05-23 20:42 菜鸟哟 阅读(54) 评论(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 菜鸟哟 阅读(42) 评论(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 菜鸟哟 阅读(96) 评论(0) 推荐(0)