随笔分类 -  剑指Offer

摘要:/** * 剑指 Offer 26. 树的子结构 * https://leetcode.cn/problems/shu-de-zi-jie-gou-lcof/ * */ public class Solution { public boolean isSubStructure(TreeNode A, 阅读全文
posted @ 2022-06-26 23:41 廖子博 阅读(19) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 25. 合并两个排序的链表 * https://leetcode.cn/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/ * */ public class Solution { public ListNode me 阅读全文
posted @ 2022-06-26 23:20 廖子博 阅读(16) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 22. 链表中倒数第k个节点 * https://leetcode.cn/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/ * * 思路:快慢指针 * */ public class Solution { pu 阅读全文
posted @ 2022-06-26 21:54 廖子博 阅读(16) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面 * https://leetcode.cn/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/ * * 思路:快排思想 * */ 阅读全文
posted @ 2022-06-26 21:47 廖子博 阅读(21) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 18. 删除链表的节点 * https://leetcode.cn/problems/shan-chu-lian-biao-de-jie-dian-lcof/ * * 思路:双指针 * */ public class Solution { public ListNode 阅读全文
posted @ 2022-06-26 19:53 廖子博 阅读(14) 评论(0) 推荐(0) 编辑
摘要:大数问题 /** * 剑指 Offer 17. 打印从1到最大的n位数 * https://leetcode.cn/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/ * * 思路:回溯思想 * 考虑大数问题(用字符串或数组表示大数) * */ pu 阅读全文
posted @ 2022-06-26 19:28 廖子博 阅读(19) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 16. 数值的整数次方 * https://leetcode.cn/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/ * * 思路:快速幂 * x^n = x^a * x^b (n=a+b) * 13 = 1101 (十进制转二进制 阅读全文
posted @ 2022-06-26 11:41 廖子博 阅读(27) 评论(0) 推荐(0) 编辑
摘要:位移 /** * 剑指 Offer 15. 二进制中1的个数 * https://leetcode.cn/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/ * * 思路:位移 * */ public class Solution1 { public int ham 阅读全文
posted @ 2022-06-26 11:05 廖子博 阅读(19) 评论(0) 推荐(0) 编辑
摘要:深度优先 /** * 剑指 Offer 13. 机器人的运动范围 * https://leetcode.cn/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/ * * 思路:深度优先 * */ public class Solution1 { private 阅读全文
posted @ 2022-06-25 22:42 廖子博 阅读(16) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 12. 矩阵中的路径 * https://leetcode.cn/problems/ju-zhen-zhong-de-lu-jing-lcof/ * * 思路:深度优先搜索 * */ public class Solution { private char[][] bo 阅读全文
posted @ 2022-06-25 21:25 廖子博 阅读(22) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 11. 旋转数组的最小数字 * https://leetcode.cn/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/ * * 输入:numbers = [3,4,5,1,2] * 输出:1 * */ public 阅读全文
posted @ 2022-06-25 20:41 廖子博 阅读(17) 评论(0) 推荐(0) 编辑
摘要:动态规划 /** * 剑指 Offer 10- I. 斐波那契数列 * https://leetcode.cn/problems/fei-bo-na-qi-shu-lie-lcof/ * 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。 * * 阅读全文
posted @ 2022-06-24 23:05 廖子博 阅读(22) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 09. 用两个栈实现队列 * https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/ * */ public class CQueue { private Deque<Integer> 阅读全文
posted @ 2022-06-24 22:16 廖子博 阅读(19) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 07. 重建二叉树 * https://leetcode.cn/problems/zhong-jian-er-cha-shu-lcof/ * 思路:前序遍历数组的第一个结点是根结点,在中序遍历数组中找到根结点,根结点左边是是左子树的元素,根结点右边是右子树的元素 * 递 阅读全文
posted @ 2022-06-24 21:35 廖子博 阅读(14) 评论(0) 推荐(0) 编辑
摘要:递归 /** * 剑指 Offer 06. 从尾到头打印链表 * 思路:递归或栈 * */ public class Solution { public int[] reversePrint(ListNode head) { return reverse(head, 0, null); } priv 阅读全文
posted @ 2022-06-24 20:20 廖子博 阅读(17) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 05. 替换空格 * 思路:如果给定的字符数组能够容纳替换后的字符串,则可以从后开始替换 * */ public class Solution { public String replaceSpace(String s) { // 统计空格数量 int spaces = 阅读全文
posted @ 2022-06-24 19:56 廖子博 阅读(19) 评论(0) 推荐(0) 编辑
摘要:/** * 剑指 Offer 04. 二维数组中的查找 * https://leetcode.cn/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/ * 思路:从右上角或左下角开始查找,每次都能排除一行或一列 * */ public class Solut 阅读全文
posted @ 2022-06-24 19:47 廖子博 阅读(13) 评论(0) 推荐(0) 编辑
摘要:HashSet /** * 题目:找出数组中重复的数字。 * https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/ * * 利用哈希集合在 O(1) 时间复杂度判断元素是否在集合中 * */ public class S 阅读全文
posted @ 2022-06-24 19:27 廖子博 阅读(16) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示