上一页 1 2 3 4 5 6 7 8 9 10 ··· 13 下一页
摘要: /* 数值的整数次方 可分为三种情况, n为负整数,n为0,n为正整数 1负整数: 需要将 x 转为 1/x , n 转为 -n 2为0 : 返回 1 3为正整数,考虑是偶数,还是奇数 偶数 : myPow(x,n) 转为 myPow(x * x , n/2) 奇数 : myPow(x,n) 转为 阅读全文
posted @ 2020-12-13 02:03 peanut_zh 阅读(72) 评论(0) 推荐(0)
摘要: //学习大佬的,dfs + 剪枝class Solution { public boolean exist(char[][] board, String word) { char[] words = word.toCharArray(); for(int i = 0;i < board.length 阅读全文
posted @ 2020-12-12 23:03 peanut_zh 阅读(87) 评论(0) 推荐(0)
摘要: //二分查找法 class Solution { public int minArray(int[] numbers) { //定义左、右边界 int left = 0; int right = numbers.length - 1; while(left < right){ //中间的元素 int 阅读全文
posted @ 2020-12-12 22:00 peanut_zh 阅读(87) 评论(0) 推荐(0)
摘要: class Solution { public int numWays(int n) { int a = 1, b = 1, sum; for(int i = 0;i < n;i++){ sum = (a + b) % 1000000007; a = b; b = sum; } return a; 阅读全文
posted @ 2020-12-12 20:34 peanut_zh 阅读(76) 评论(0) 推荐(0)
摘要: // class Solution { // public int fib(int n) { // int a = 0,b = 1, sum; // for(int i = 0;i < n;i++){ // sum = (a + b) % 1000000007; // a = b; // b = s 阅读全文
posted @ 2020-12-12 20:24 peanut_zh 阅读(72) 评论(0) 推荐(0)
摘要: // 一种用LinkedList ,一种用Stack LeetCode 232题 class CQueue { private Stack<Integer> s1,s2; public CQueue() { s1 = new Stack<>(); s2 = new Stack<>(); } publ 阅读全文
posted @ 2020-12-12 17:44 peanut_zh 阅读(73) 评论(0) 推荐(0)
摘要: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ /* 1.用一个栈,来实现倒序输出 阅读全文
posted @ 2020-12-12 15:25 peanut_zh 阅读(59) 评论(0) 推荐(0)
摘要: //Java语言中,字符串是「不可变」的类型,即无法直接修改字符串的某一位字符,需要新建一个字符串实现。 class Solution { public String replaceSpace(String s) { //新建一个字符串sb StringBuilder sb = new String 阅读全文
posted @ 2020-12-12 12:50 peanut_zh 阅读(65) 评论(0) 推荐(0)
摘要: //暴力法 时间复杂度 O(m * n) //根据排序的规律观察,得到类似2叉搜索树的解法 O(m + n) class Solution { public boolean findNumberIn2DArray(int[][] matrix, int target) { //判空 if(matri 阅读全文
posted @ 2020-12-12 12:31 peanut_zh 阅读(97) 评论(0) 推荐(0)
摘要: /* 1、最直观的想法是,我直接一个俩层循环,一个一个比,不过效率太差了; 2、第二种思路,长度为n的数组,数字都在 0~ n-1 的范围,这样如果我们把这个数组按升序排列 扫描这个数组的元素,若数组不重复,会发现 第 i 个元素必定 为 i。 所以得出这样的思路 1)从头扫描数组,下标为 i 的数 阅读全文
posted @ 2020-12-12 11:54 peanut_zh 阅读(84) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 13 下一页