随笔分类 - 剑指Offer
摘要:题目 力扣链接:https://leetcode.cn/problems/find-all-numbers-disappeared-in-an-array 给你一个含 n 个整数的数组 nums ,其中 nums[i] 在区间 [1, n] 内。请你找出所有在 [1, n] 范围内但没有出现在 nu
阅读全文
摘要:3. 无重复字符的最长子串 给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。 输入: s = "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 这题主要的思路是滑动窗口: 滑动窗口是什么? 解法: class Solution
阅读全文
摘要:冒泡排序: 稳定排序,时间复杂度O(n) void BubbleSort(int[] nums){ int len=nums.length; for(int i=0;i<len;i++){ for(int j=0;j<len-1-i;j++){ if(nums[j]>nums[j+1]){ //稳定
阅读全文
摘要:思路:使用Java自带BitSet函数,将手机号分为两段(15555555555 -> 155+55555555) public class demo { public static void main(String[] args) { Map<Integer, BitSet> map = new
阅读全文
摘要:## 注意: 前中后序是遍历二叉树过程中处理每一个节点的三个特殊时间点 前序:刚刚进入一个节点执行 中序:左子树全部执行完,准备执行右子树前 后续:离开节点前执行 ## 二叉树前中后序遍历框架 ### 1.递归框架 ```java void traverse(TreeNode head){ if(h
阅读全文
摘要:题目: 用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) 示例: 输入: ["CQueue","appendTail","de
阅读全文
摘要:1. 描述 要求: 数组 2. 有序 2. 代码 class Solution { public int search(int[] nums, int target) { int left = 0; int right = nums.length - 1; while (left <= right)
阅读全文
摘要:堆:是一颗完全二叉树。(所以可以用数组表示) {0,1,2,3,4,5} 0是父亲节点 1,2是0的子节点 知道父亲节点为i,则左孩子便是(2 * i)+1,右孩子是(2 * i)+2 "左孩子+1" 知道孩子节点为i,父亲节点为(i-1)/2,此处写一个是由于java自动向下取整 /** * @a
阅读全文
摘要:#include <iostream> using namespace std; void QuickSort(int *array,int left,int right) { if(left>=right) { return; } else { int Base=array[left]; int
阅读全文