博客园 首页 私信博主 显示目录 隐藏目录 管理 动画
摘要: 1 public int Fibonacci(int n) { 2 //如果n=0,返回0,如果n=1或者n=2,返回1 3 if (n 0 ? 1 : 0; 5 } 6 int f1 = 1;//f1指针指向前面一个数 7 int f2 = 1;//f1指针指向后面一个数 8 for... 阅读全文
posted @ 2019-04-25 18:40 影梦 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 1 public int minNumberInRotateArray(int[] array) { 2 // 1、如果输入的数组为空,则返回0(返回0是题目要求的) 3 // 2、如果输入的数组的内容为空,则返回0(返回0是题目要求的) 4 if (array == null || array.length == 0) { 5 ... 阅读全文
posted @ 2019-04-25 18:22 影梦 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 1 // stack1用来表示入栈 2 Stack stack1 = new Stack(); 3 // stack2用来表示出栈 4 Stack stack2 = new Stack(); 5 6 // 队列的入队,就用stack1进行入栈 7 public void push(int node) { 8 stack1... 阅读全文
posted @ 2019-04-25 16:37 影梦 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 1 public ArrayList printListFromTailToHead(ListNode listNode) { 2 // 定义一个ArrayList,用来存放翻转链表结果 3 ArrayList list = new ArrayList(); 4 if (listNode == null) { 5 ... 阅读全文
posted @ 2019-04-25 11:39 影梦 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 1 public String replaceSpace(StringBuffer str) { 2 // 1、如果输入的字符串为空,则返回空字符串,如果返回null,牛客网通不过 3 // 2、如果输入的字符串的内容为空,则返回空字符串 4 if (str == null || str.length() == 0) { 5 ... 阅读全文
posted @ 2019-04-25 11:22 影梦 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 1 public boolean Find(int target, int[][] array) { 2 // 1、判断输入进来的数组array是否为空,array == null 3 // 2、判断输入进来的数组array的内容是否为空,array.length == 0 4 if (array == null || array.leng... 阅读全文
posted @ 2019-04-25 10:57 影梦 阅读(127) 评论(0) 推荐(0) 编辑
摘要: public void mergeSort(int[] array, int low, int high) { int mid = low + (high - low) / 2; if (low < high) { mergeSort(array, low, mid); mergeSort(arra 阅读全文
posted @ 2019-03-17 16:10 影梦 阅读(165) 评论(0) 推荐(0) 编辑
摘要: public void quickSort(int[] array, int low, int high) { if (low >= high) { return; } int left = low; int right = high; int mid = array[left]; ... 阅读全文
posted @ 2019-03-17 15:59 影梦 阅读(106) 评论(0) 推荐(0) 编辑
摘要: public void bubbleSort(int[] array) { boolean flag; for (int i = 0; i < array.length - 1; i++) { flag = false; for (int j = array.length - 1; j > i; j 阅读全文
posted @ 2019-03-17 15:52 影梦 阅读(121) 评论(0) 推荐(0) 编辑
摘要: public void selectionSort(int[] array) { for (int i = 0; i < array.length; i++) { int minIndex = i; for (int j = i + 1; j < array.length; j++) { if (a 阅读全文
posted @ 2019-03-17 15:47 影梦 阅读(92) 评论(0) 推荐(0) 编辑