自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(33)
  • 收藏
  • 关注

原创 leetcode 27 移除元素

从前向后遍历数组,在遍历的过程中使用变量removedCount记住值等于val的元素的个数。最后将数组的长度设置为最终保留下来的元素的个数。

2023-03-01 19:20:04 97 1

原创 leetcode 704 二分查找

如果target > nums[mid] 则表示target所在的区间在[mid +1 , right] 这个区间。如果target < nums[mid] 则表示target所在的区间在[left , mid-1] 这个区间。如果target == nums[mid] 则表示找到了值等于target的元素的下标,搜索结束。每次从[left , right] 这个区间中寻找与target相等的元素。如果不懂二分查找,直接遍历一次数组也能找出答案,时间复杂度为O(n)。

2023-03-01 19:12:12 72

原创 Arm64-OS实验 控制台输出hello arm64!

1.代码环境代码的编写使用 vscode 编辑器 ,使用gcc 交叉编译工具链进行编译,运行在qemu 模拟器上,代码debug调试 使用 gdb 。 整体环境部署在docker 环境中。2. 仿照Linux 创建目录在上一篇文章中,labs 目录下 创建一个 lab1目录。 本节的实验代码全部书写在lab1中。 lab1目录的创建参考如下结构。其中蓝色字体为目录 , 我们的代码编译需要使用 make 进行控制 自动化进行编译。因此我们创建了若干Makefile 进行编译控制代码的书写。关于Ma

2021-02-25 15:43:37 1143 1

原创 Arm64操作系统实验 docker环境搭建

1.在docker 中拉取Linux 镜像在一个空文件夹中创建文件 Dockerfile 写入如下命令,拉取一个基础的docker 镜像FROM daocloud.io/library/ubuntu:16.04RUN apt-get update && apt-get upgrade -y WORKDIR /home/labs #设置工作目录的路径在终端中 进入Dockerfile 文件所在的文件夹 执行如下命令:docker build -t os_lab:0.1 .

2021-02-24 10:37:35 1484

原创 最短路径算法-Dijkstra

最短路径问题,我么一般也是在带权图中进行求解。即对于一个图来说,从一个点到另一个点我们要找到一个路径,这个路径上的总权值最小。一般我们在路径规划非常常见。单源最短路径我们在说带权图的最短路径的时候,我们从一个固定的点出发,一直走到图中任意一个目标顶点的路径。带权图和无权图的最短路径求法有什么不同。 对于无权图的,我们只要边数越少,路径的总长度肯定越少,但是带权图就不一样了, 由于边上有权值,...

2020-04-28 18:04:39 237

原创 带权图和最小生成树

带权图一言以蔽之,我们的图中,边上带有权值。 入过我们的图带上权值的话,存储图的结构就不能用 TreeSet 了,这是因为 set只能帮助我们存储当前顶点的邻接点, 不能存储与这个邻接点 之间 边的权值。 因此,为了可以方便地存储 两个数据,准确说是一对数据,我们很容易想到用 映射,也就是TreeMap <Interger ,Integer>import java.io.Fil...

2020-04-28 13:23:09 2100

原创 欧拉回路和欧拉路径

什么是欧拉回路从一个点出发,沿着边行走,经过每一个边恰好一次(要经过所有的边),之后在回到出发点。 有哈密尔顿回路,并不一定存在欧拉回路。欧拉回路一定遍历了所有顶点。但是存在欧拉回路是不是一定存在哈密尔顿回路呢? 其实不是的,因为哈密尔顿回路要求每一个顶点只能遍历一次。欧拉回路不要求每一个顶点只遍历一次。欧拉回路是欧拉研究格尼斯堡七桥问题发现的。 也就是通常大家说的 一笔画问题 很长时间...

2020-04-27 19:40:45 729

原创 PAT 1002 多项式相加

1002 A+B for Polynomials (25分)This time, you are supposed to find A+B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and e...

2020-04-25 23:33:46 175

原创 PAT 1001简单模拟

1001 A+B Format (20分)Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specifi...

2020-04-25 22:40:49 127

原创 图论搜索与人工智能BFS

笔试中的BFS问题-LeetCode1091在一个 N × N 的方形网格中,每个单元格有两种状态:空(0)或者阻塞(1)。一条从左上角到右下角、长度为 k 的畅通路径,由满足下述条件的单元格 C_1, C_2, ..., C_k 组成:相邻单元格 C_i 和 C_{i+1} 在八个方向之一上连通(此时,C_i 和 C_{i+1} 不同且共享边或角)C_1 位于 (0, 0)(即,值为...

2020-04-25 17:32:13 631

原创 图论问题建模

算法笔试中图论问题的书写 一般不用我们先创建图,题目一般都会给出图,我们直接在给定的数据结构上进行问题的求解。LeetCode 785 判断二分图给定一个无向图graph,当这个图为二分图时返回true。如果我们能将一个图的节点集合分割成两个独立的子集A和B,并使图中的每一条边的两个节点一个来自A集合,一个来自B集合,我们就将这个图称为二分图。graph将会以邻接表方式给出,graph...

2020-04-24 22:43:26 541

原创 图的广度优先遍历及其应用

广度优先遍历图的广度优先遍历和树的广度优先遍历本质是一样的。 由于图大多有环,我们需要在进行图的广度优先遍历时,我么需要记住那些顶点已经被遍历过。 树的广度优先遍历又叫树的层序遍历,通常使用一个队列 来实现。import java.util.ArrayList;import java.util.LinkedList;import java.util.Queue;public class...

2020-04-23 17:55:43 1303

原创 图的深度优先遍历的应用

求无向图的连通分量的个数在构造函数中,每次执行一次dfs 就会完整遍历一个连通分量。连通分量的个数我们用count 来记录。public class CC { private Graph G; private boolean[] visited; private int count = 0; // 连通分量的个数 public CC (Graph G) { ...

2020-04-22 23:39:12 1059

原创 图的深度优先遍历

遍历的意义数据结构是存储数据的,在存储数据后,必然是要进行增删改查操作的,那么我们就需要至少一中方式对存放进数据结构进行遍历。 每一种数据结构都必须有遍历的方式。比如树的遍历。很多算法的本质就是遍历。图论更是如此。 图通常不是用来存储数据,而是存储一种拓扑关系,为了获得这种关系,通常需要把整个图遍历一遍,同时还要在遍历时记录一些东西。相比较而言,在树(一种特殊的图)中我们在某些情况下不用全部进...

2020-04-21 19:56:33 776

原创 图的基本表示

图的分类:我们的数据结构大体可以分为三类 :线性结构 、 树结构 、图结构 这三种结构都是既可以用 数组表示 也可以用链表表示。图的表示需要表示的就是图的顶点和图的边。顶点:vertex 边: edge 无向图:undirected graph 有向图 : directed graph有些地方建模需要用有向图 ,有些需要无向图 : 比如交通网络需要无向图 。 比如微...

2020-04-21 16:19:23 296

原创 PAT1003 带权图的最短路径

1003 Emergency (25分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams i...

2020-04-20 16:38:46 314

原创 PAT1076图的遍历(微博转发人数)

1076 Forwards on Weibo (30分)Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with...

2020-04-20 15:23:54 162 1

原创 PAT1034带权图遍历

1034 Head of a Gang (30分)One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a r...

2020-04-18 22:12:58 573

原创 PAT1021 最大高度的树的根节点

1021 Deepest Root (25分)A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a hi...

2020-04-18 17:59:37 134

原创 PAT1013删除顶点后的连通分量的个数

1013 Battle Over Cities (25分)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We m...

2020-04-18 15:59:51 333

原创 PAT1066 平衡二叉树的根节点

1066 Root of AVL Tree (25分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by m...

2020-04-18 00:19:17 669

原创 PAT1099构建BST输出层序遍历

1099 Build A Binary Search Tree (30分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys l...

2020-04-17 17:42:56 160

原创 PAT1064 完全二叉搜索树

1064 Complete Binary Search Tree (30分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys ...

2020-04-17 16:39:53 184

原创 PAT1043给定序列是否是BST或其镜像的前序

1043 Is It a Binary Search Tree (25分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys l...

2020-04-17 15:57:17 97

原创 PAT1053多叉树带权路径搜索回溯算法

1053 Path of Equal Weight (30分)Given a non-empty tree with root R, and with weight W**i assigned to each tree node T**i. The **weight of a path from **R to L is defined to be the sum of the weights ...

2020-04-16 23:05:35 513

原创 PAT1004多叉树 叶子节点的个数

1004 Counting Leaves (30分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one te...

2020-04-16 21:42:33 860

原创 PAT1106多叉树

1106 Lowest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting...

2020-04-16 21:00:30 221 2

原创 PAT1094 多叉树

1094 The Largest Generation (25分)A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation wi...

2020-04-16 17:26:57 116

原创 PAT1090多叉树

1090 Highest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Startin...

2020-04-16 16:24:44 93

原创 PAT1079多叉树

1079 Total Sales of Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting ...

2020-04-15 22:52:47 133

原创 PAT1102翻转二叉树

数据结构 翻转二叉树 11021102 Invert a Binary Tree (25分)The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a w...

2020-04-15 21:19:19 81

原创 PAT1086二叉树的创建+遍历

1086 Tree Traversals Again (25分)An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered fr...

2020-04-15 16:07:10 113

原创 PAT1020二叉树遍历

1020 Tree Traversals (25分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order tr...

2020-04-14 23:30:51 142

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除