文章格式模板 提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录一、pandas是什么?二、使用步骤1.引入库2.读入数据一、pandas是什么?二、使用步骤1.引入库import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport warningswarnings.filterwarnings('ignore')import sslssl._c
剑指 Offer 54. 二叉搜索树的第k大节点 java:二叉搜索树是按照中序遍历排序,要找第k大的数,可以用反中序遍历,发现res的长度==k就中止遍历。class Solution { List<Integer> res = new ArrayList<>(); public int kthLargest(TreeNode root, int k) { kthLargestCore(root, k); return res.get(res.size() - 1); .
剑指 Offer 59 - I. 滑动窗口的最大值 java:维持一个队列que,遍历数组,每次把que后边小于nums[i]的数字出队再加入nums[i]当遍历的下标i达到窗口大小的时候把结果(队首加入res),接着判断目前窗口的第一个数字和队首值一不一样,一样需要出队。class Solution { public int[] maxSlidingWindow(int[] nums, int k) { if (nums.length < 0 || k == 0) return new int[.
剑指 Offer 56 - II. 数组中数字出现的次数 II java:把数组中每个位置的1出现次数相加这个位置1出现的次数%3为1说明出现一次的这个数字这个位置是1。class Solution { public int singleNumber(int[] nums) { int res = 0; for (int i = 0; i < 32; i++) { int cmp = 1 << i; int count = 0; fo.
剑指 Offer 56 - I. 数组中数字出现的次数 java:先把数组的数字异或在一起tem<相异为1>找到tem第一个为1的数字<两个出现一次的数字异或后说明两个数在这个位置上数字不一样>把数组的数字以这个位置上的数字分类分别异或,最后得到两个数字class Solution { public int[] singleNumbers(int[] nums) { int tem = 0; for (int i = 0; i < nums.length; i++) { .
剑指 Offer 59 - II. 队列的最大值 java:用一个队列deq保存最大值,一个队列que保存所有值push_back val时,把deq尾小于val的值都删除再入val最大值一直在deq的首部pop的时候如果pop的值和deq队首的值一样就把deq也popclass MaxQueue { LinkedList<Integer> que, dque; public MaxQueue() { que = new LinkedList<>(); dque = new.
110. 平衡二叉树 java:class Solution { public boolean isBalanced(TreeNode root) { if (isBalancedCore(root) == -1) return false; return true; } public int isBalancedCore(TreeNode root) { if (root == null) return.
剑指 Offer 28. 对称的二叉树 java:class Solution { public boolean isSymmetric(TreeNode root) { if (root == null) return true; return isSymmetricCore(root.left, root.right); } public boolean isSymmetricCore(TreeNode left, TreeNode right) { .
82. 删除排序链表中的重复元素 II(重复节点不加入) java:pre指向结果的尾巴,node和next用于过滤重复的节点class Solution { public ListNode deleteDuplicates(ListNode head) { if (head == null) return head; ListNode pre = new ListNode(-1); ListNode res = pre; ListNode node = head.
107. 二叉树的层次遍历 II(从上往下打印) java:class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> levelOrderBottom(TreeNode root) { if (root == null) return res; LinkedList<TreeNode> que.
排序基础 1. 冒泡排序(1) 代码//第一种最简单的冒泡排序,下面代码将数组数字递增排列;class Solution {public: vector<int> bubbleSort(vector<int> vec) { int size = vec.size(); for (int i = size - 1; i > 0; i--) {//每一次遍历是把遍历到的数字放在下面的循环向上冒泡; for (int j = size - 1; j > 0; j-
112. 路径总和(返回boolean) java:class Solution { public boolean hasPathSum(TreeNode root, int sum) { return hasPathSumCore(root, sum) == 1 ? true : false; } public int hasPathSumCore(TreeNode root, int sum) {//注!!返回有三种状态可以用int返回判断 if (root == null) .
113. 路径总和 II(返回数组结果) java:class Solution { public List<List<Integer>> res = new ArrayList<>(); public List<Integer> path = new ArrayList<>(); public List<List<Integer>> pathSum(TreeNode root, int sum) { pathSumCor.
19. 删除链表的倒数第N个节点 java:class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode l1 = head, l2 = head; ListNode l3 = new ListNode(-1); ListNode res = l3;//注!!需要考虑删除的是head节点 l3.next = head; for (int i = 0.
剑指 Offer 52. 两个链表的第一个公共节点 java:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode getIntersec.
组合之22. 括号生成 java:回溯:记录左右括号的数量,左括号小于n就继续加左括号,右括号比左括号少就加右括号,最后在path的结果等于2*n就收集结果。class Solution { List<String> res; StringBuilder path; public List<String> generateParenthesis(int n) { res = new ArrayList<>(); path = new .
剑指 Offer 30. 包含min函数的栈 java:两个栈,一个保存最小值,一个正常保存class MinStack { public LinkedList<Integer> st; public LinkedList<Integer> minSt; /** initialize your data structure here. */ public MinStack() { st = new LinkedList<>(); minSt = n.
剑指 Offer 10- I. 斐波那契数列 java:class Solution { public int fib(int n) { if (n == 0) return 0;//注!! if (n == 1) return 1; int tem1 = 0, tem2 = 1, sum = 0; while (n >= 2) { sum = (tem1 + tem2) % 1000000007;//注!!取模 tem1 .
剑指 Offer 32 - III. 从上到下打印二叉树 III(之字形) java:class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res = new ArrayList<>(); if (root == null) return res; LinkedList<TreeNode> que =.
剑指 Offer 32 - II. 从上到下打印二叉树 II(分行) java:class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res = new ArrayList<>(); if (root == null)//注!!root是空返回 return res; LinkedList<TreeN.