- 博客(207)
- 资源 (1)
- 收藏
- 关注
原创 leetcode 周赛题解--持续更新
目录39场双周赛215场周赛39场双周赛215场周赛5601-设计有序流5602-将 x 减到 0 的最小操作数5603-确定两个字符串是否接近5604-最大化网格幸福感
2020-11-15 13:56:44 460 2
原创 动态规划(1)-- 数字三角形模型
目录数字三角形摘花生最低通行费方格取数传纸条数字三角形题目-898.数字三角形import java.util.*;import java.math.*;public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] w = new int[n][n];
2020-12-25 21:08:31 257
原创 5. Trie树
class Trie{ int n; int[][] son; int[] cnt; int idx = 0; Trie(int n){ this.n = n; son = new int[n][26]; cnt = new int[n]; } public void insert(String s){ char[] c = s.toCharArray(); int p
2020-12-23 11:18:43 227
原创 4. 滑动窗口
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.LinkedList;public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(ne
2020-12-22 21:44:06 234
原创 3.前缀和
前缀和795. 前缀和package acwing;import java.io.BufferedReader;import java.io.InputStreamReader;public class T795 { public static void main(String[] args) throws Exception{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.i.
2020-12-22 16:11:13 112
原创 2.二分查找
public static int binarySearchLeft(int[] nums, int left, int right, int key){ while (left < right){ int mid = (left + right ) / 2; if (nums[mid] >= key){ right = mid; } else{ left = mid + 1
2020-12-22 15:19:23 82
原创 1. 排序
public static void qSort(int[] arr, int left, int right){ if (left >= right) return; int i = left - 1, j = right + 1; int key = arr[left]; while (i < j){ while (arr[++i] < key); while (arr[--j] > key); i
2020-12-22 11:19:56 166
原创 leetcode-219场周赛
目录1688. 比赛中的配对次数1689. 十-二进制数的最少数目1690. 石子游戏 VII1691. 堆叠长方体的最大高度1688. 比赛中的配对次数题目-1688. 比赛中的配对次数每轮只会淘汰一个人,那么总共需要淘汰n - 1个人,一共n - 1 场class Solution { public int numberOfMatches(int n) { return n - 1; }}1689. 十-二进制数的最少数目题目-1689. 十-二进制数的最
2020-12-14 11:34:37 208
原创 leetcode-217场周赛
目录5613. 最富有客户的资产总量5614. 找出最具竞争力的子序列5615. 使数组互补的最少操作次数5616. 数组的最小偏移量5613. 最富有客户的资产总量题目-5613. 最富有客户的资产总量只会水水简单题了。扫描求和,选最大,ac,比赛结束。class Solution { public int maximumWealth(int[][] accounts) { int[] sum = new int[accounts.length]; for
2020-11-29 19:41:03 140 1
原创 leetcode-40场双周赛
目录5557. 最大重复子字符串5558. 合并两个链表5560. 设计前中后队列5559. 得到山形数组的最少删除次数5557. 最大重复子字符串题目-5557. 最大重复子字符串比赛的时候写的超级复杂,最简单的就是一次构造k个重复的word,查查有没有。class Solution { public int maxRepeating(String sequence, String word) { int cnt = 0; String ss = word;
2020-11-29 00:28:08 307
原创 leetcode-216场周赛
这里写目录标题1662. 检查两个字符串数组是否相等1663. 具有给定数值的最小字符串1664. 生成平衡数组的方案数1665. 完成所有任务的最少初始能量1662. 检查两个字符串数组是否相等题目-1662. 检查两个字符串数组是否相等从左到右依次合并word1和word2,然后比较合并后的单词是否相同即可。class Solution { public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
2020-11-27 15:53:50 195
原创 leetcode-213场周赛
目录1640. 能否连接形成数组1641. 统计字典序元音字符串的数目1642. 可以到达的最远建筑1643. 第 K 条最小指令1640. 能否连接形成数组题目-1640. 能否连接形成数组遍历arr中的每一个元素,如果与pieces中的第一个元素相等,则依次遍历pieces中的元素。class Solution { public boolean canFormArray(int[] arr, int[][] pieces) { boolean flag = true;
2020-11-27 11:08:37 190
原创 leetcode-215场周赛
目录5601-设计有序流5602. 将 x 减到 0 的最小操作数5603. 确定两个字符串是否接近5604. 最大化网格幸福感5601-设计有序流题目-5601-设计有序流最开始没有看明白什么意思,其实,简单来说,就是,维护一个String数组,一次在数组中插入字符串,同时维护一个ptr指针,如果当前插入的位置与ptr指针指向相同,则遍历至数组为空,同时更改ptr指针位置。否则,ptr指针向下指一个。class OrderedStream { String[] str = null;
2020-11-15 13:41:30 266
原创 leetcode-113 路径总和 II - 二叉树
leetcode-113 路径总和 II这个题是leetcode-112 路径总和的进阶,只需要额外开个数组记录路径。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution {
2020-11-12 11:54:13 125 1
原创 leetcode-112 路径总和-二叉树
leetcode-112 路径总和计算根节点到叶子节点的和,然后和目标值进行比较。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { private boolean
2020-11-12 11:40:22 175 1
原创 leetcode-111 二叉树的最小深度-二叉树
leetcode-111 二叉树的最小深度计算根节点到叶子节点的距离,取最小/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int
2020-11-12 11:37:46 80
原创 leetcode-110 平衡二叉树-平衡二叉树
leetcode-110 平衡二叉树平衡二叉树要求所有节点的左右子树的高度差小于1,因此,只需在遍历的时候返回其左右子树的深度。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val =
2020-11-12 11:13:38 156
原创 leetcode-108 将有序数组转换为二叉搜索树-二叉树
leetcode-108 将有序数组转换为二叉搜索树最简单的一个想法,取数组中间值为根,左边构建左子树,右边构建右子树。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution {
2020-11-12 10:58:39 150 1
原创 leetcode-107 二叉树的层次遍历 II -二叉树
leetcode-107 二叉树的层次遍历 II正常层序遍历,最后将数组翻转/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public List<List
2020-11-12 10:50:26 81
原创 leetcode-106 从中序与后序遍历序列构造二叉树-二叉树
leetcode-106 从中序与后序遍历序列构造二叉树这题和leetcode-105一样,后序最后一个节点是根节点,然后在中序中划分子树即可。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class
2020-11-12 10:40:54 116 1
原创 leetcode-105 从前序与中序遍历序列构造二叉树-二叉树
leetcode-105 从前序与中序遍历序列构造二叉树前序的第一个节点是根节点,然后在中序中找到这个节点的位置,该位置前为左子树,后为右子树。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class
2020-11-12 10:18:16 128 5
原创 leetcode-104 二叉树的最大深度-二叉树
leetcode-104 二叉树的最大深度随便一种遍历方式,遍历的同时记录深度,水题。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { private int ma
2020-11-12 09:34:33 79
原创 leetcode-103 二叉树的锯齿形层次遍历-二叉树
leetcode-103 二叉树的锯齿形层次遍历这题与102题无异,只需对于保存结果的偶数行进行一次反转。可用(Collections.reverse())/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */
2020-11-12 09:29:53 134 2
原创 leetcode-102 二叉树的层序遍历
leetcode-102 二叉树的层序遍历嗯,简单的bfs,由于每层需要构成一个数组,因此在遍历的时候,每层节点一起处理。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution {
2020-11-11 21:50:21 131
原创 leetcode-101 对称二叉树-二叉树
leetcode-101 对称二叉树与100题类似,可看做p,q两棵树的左右子树互相对比,注意判空。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { private
2020-11-11 21:16:23 164
原创 leetcode-100 相同的树-二叉树
100 相同的树同步遍历两棵树,比对是否值相等,注意判空。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, Tree
2020-11-11 21:07:46 100
原创 leetcode-98 验证二叉搜索树-二叉树
98 验证二叉搜索树二叉搜索树的中序遍历为单调递增。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { private boolean flag = true;
2020-11-11 20:43:50 99
原创 leetcode-94 二叉树的中序遍历-二叉树
基础模板题,利用递归遍历二叉树/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, Tree
2020-11-11 20:17:38 84
原创 leetcode-124 二叉树中的最大路径和-二叉树
124二叉树中的最大路径和在树中,每个节点都可以看做是一颗以该节点为根的子树,同时又作为其他根的子节点(根节点除外),因此,只需单独讨论两种情况。当A作为根节点的时候,最大值为B-A-C当A作为子节点的时候,最大值为Max(B, C) + A注:当子节点小于0时,则舍弃该节点/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; *
2020-11-11 17:32:38 108
原创 HDF5库安装 c++ vs2017
1.下载对应的压缩包,https://www.hdfgroup.org/downloads/hdf5/2.安装下载包,一定要记住安装位置3.选择vc++目录,在包含文件中添加include的路径,在库目录添加lib的路径 4.选择链接器,在附加依赖库中添加szip.lib;zlib.lib;hdf5.lib;hdf5_cpp.lib;5.选择c/c++的代码生成,讲运行...
2018-12-03 14:32:28 4029 6
原创 c++ gsl库安装
Linux系统1. 在gnu的ftp站点http://ftp.gnu.org/gnu/gsl/ 上, 下载最新的gsl-2.x.tar.gz2. 解压下载好的gsl-2.x.tar.gz 压缩包,$tar -zxvf gsl-2.x.tar.gz. 直接解压在了Downloads文件夹中。3. $ cd gsl-2.x, 进入到gsl文件夹中, 运行$./configure --pr...
2018-11-01 10:04:46 3489 1
原创 python爬虫(四)编程语言排名爬虫
import requestsfrom bs4 import BeautifulSoupimport bs4 def getHTMLText(url): try: r = requests.get(url) r.raise_for_status() r.encoding = r.apparent_encoding r...
2018-08-11 23:21:50 2109
原创 python爬虫(三)Beautiful Soup库使用
一、Beautiful Soup库安装window或Linux均可使用命令 pip install beautifulsoup4二、HTML文档示例<!--http://python123.io/ws/demo.html--><html> <head> <title> This is a python demo page...
2018-08-06 12:21:24 374
原创 python--pip升级
使用pip安装插件时报错You are using pip version 9.0.3, however version 18.0 is available.You should consider upgrading via the 'python -m pip install --upgrade pip' command.升级命令python -m pip install --up...
2018-08-06 11:19:56 225
原创 python爬虫(二)requests网络爬取实战
1.京东商品页面爬取import requestsurl = "https://item.jd.com/2967929.html"try: r = requests.get(url) r.raise_for_status() r.encoding = r.apparent_encoding print(r.text)except: print("...
2018-08-06 11:08:13 925
原创 python爬虫(一)requests使用
一.requests库安装window或Linux均可使用命令 pip install requests二、requests主要方法 方法 说明 requests.request() 构造一个请求,支持一下各方法的基础方法 requests.get...
2018-08-05 23:36:49 366
原创 Python 之列表
1.基本操作#输出color=['red','green','purple','blue']print(color)#索引输出print(color[0])#修改color[0] = 'white'print(color)#在末尾添加color.append('black')print(color)#插入元素color.insert(0,'yellow')p...
2018-08-05 09:28:25 244
原创 Linux设置初始root密码
第一步:sudo passwd root第二步:[sudo] password for you: ---> 输入你的密码(你现在这个用户的密码)第三步:Enter new UNIX password: ---> 设置root 密码第四步:Retype new UNIX password: ---> 重复密码第五步:完成...
2018-08-05 09:00:36 8109
原创 2018ACM-ICPC个人总结
3月31日,郑州轻工业学院,天梯赛团体程序设计大赛,铜首,差两分,全国团队二等奖(遗憾+1) 4月1日,圈钱杯省赛,这个不按套路出牌的玩意,五个编程题,一心想优化的我,最后,特么两个编程题没过样例就交了,草草收场,心疼300块RMB。不过,大水杯没让我失望,拿到了去国赛的门票。 5月25日,北京半日游,带队老师专业拍照,五星好评!!!夜晚饭菜,五星好评!!!见到了,我们院保研的...
2018-05-28 21:07:30 1961 2
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人