上一页 1 2 3 4 5 6 7 8 9 10 ··· 14 下一页
摘要: ##6.剑指 Offer 11. 旋转数组的最小数字 二分查找 class Solution { public int minArray(int[] numbers) { int l = 0, r = numbers.length - 1; while (l < r) { int mid = ((r 阅读全文
posted @ 2022-02-10 22:24 蹇爱黄 阅读(39) 评论(0) 推荐(0)
摘要: ##1.用两个栈实现队列 用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) class CQueue { //全局声明两个栈 阅读全文
posted @ 2022-02-10 15:41 蹇爱黄 阅读(37) 评论(0) 推荐(0)
摘要: 题目链接 方法一: class Solution { public String reverseWords(String s) { //先将字符串用空格划分成字符串数组 String[] strs = s.split(" "); StringBuffer buffer = new StringBuf 阅读全文
posted @ 2022-02-09 19:11 蹇爱黄 阅读(33) 评论(0) 推荐(0)
摘要: 题目链接 class Solution { public void reverseString(char[] s) { int l = 0; int r = s.length - 1; while(l<r){ s[l] ^= s[r];//s[l] = a^b s[r] ^= s[l];//s[r] 阅读全文
posted @ 2022-02-09 18:21 蹇爱黄 阅读(24) 评论(0) 推荐(0)
摘要: 题目链接 class Solution { public boolean canWinNim(int n) { return n % 4 != 0; } } 阅读全文
posted @ 2022-02-09 15:55 蹇爱黄 阅读(80) 评论(0) 推荐(0)
摘要: 题目链接 class Solution { public int[] productExceptSelf(int[] nums) { int n = nums.length; int[] ans = new int[n]; int left = 1; //让每个数等于自己左边所有数的乘积 for(i 阅读全文
posted @ 2022-02-09 15:41 蹇爱黄 阅读(31) 评论(0) 推荐(0)
摘要: 题目链接 阅读全文
posted @ 2022-02-09 15:22 蹇爱黄 阅读(33) 评论(0) 推荐(0)
摘要: 题目链接 注意p,q必然存在树内, 且所有节点的值唯一!!! 递归思想, 对以root为根的(子)树进行查找p和q, 如果root == null || p || q 直接返回root 表示对于当前树的查找已经完毕, 否则对左右子树进行查找, 根据左右子树的返回值判断: 1. 左右子树的返回值都不为 阅读全文
posted @ 2022-02-09 15:10 蹇爱黄 阅读(31) 评论(0) 推荐(0)
摘要: 题目链接 //二叉搜索树的特性 class Solution { TreeNode res = null; public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { lca(root,p,q); ret 阅读全文
posted @ 2022-02-09 15:00 蹇爱黄 阅读(29) 评论(0) 推荐(0)
摘要: 题目链接 class Solution { public boolean isPowerOfTwo(int n) { if(n<=0) return false; //8的二进制1000 7的二进制0111 做个与操作结果为零 if((n&n-1)==0) return true; else ret 阅读全文
posted @ 2022-02-09 14:51 蹇爱黄 阅读(26) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 14 下一页