Sequence

DFS和BFS讲解及Leetcode刷题小结(2)(JAVA)

为君一笑 提交于 2020-05-08 08:20:10
上一篇文章解决了DFS的问题,这次来解决BFS的问题就简单多了 DFS实现重要依赖于堆栈/递归 ,较为简单的解决了如何遍历所有元素,以及寻求“终点”的问题。 但是,DFS虽然可以查找到到达路径,但是却找不到最短的路径,针对这一问题,给出了BFS(广度优先遍历)的算法。 首先,先给出BFS的基本过程: 与DFS不同的是,这次不再是每个分叉路口一个一个走了,而是全部,同时遍历,直到找到终点,所对应的“层数”便是最短路径所需要的步数,BFS像是在剥洋葱,一层一层的拨开,最后到达终点。 如何实现呢? 我们利用队列来实现BFS,伪代码如下: int BFS(Node root, Node target) { Queue <Node> queue; // 建立队列 int step = 0; // 建立行动步数 // initialize add root to queue; // BFS while (queue is not empty) { step = step + 1 ; // 记录此时的队列大小 int size = queue.size(); for ( int i = 0; i < size; ++ i) { //遍历队列中的元素,并将新元素加入到队列中 Node cur = the first node in queue; return step if cur is

SDNU 1119.Intelligent IME(水题)

不羁岁月 提交于 2020-05-08 07:45:58
Description We all use cell phone today. And we must be familiar with the intelligent English input method on the cell phone. To be specific, the number buttons may correspond to some English letters respectively, as shown below: 2 : a, b, c 3 : d, e, f 4 : g, h, i 5 : j, k, l 6 : m, n, o 7 : p, q, r, s 8 : t, u, v 9 : w, x, y, z When we want to input the word “wing”, we press the button 9, 4, 6, 4, then the input method will choose from an embedded dictionary, all words matching the input number sequence, such as “wing”, “whoi”, “zhog”. Here comes our question, given a dictionary, how many

算法与数据结构基础

北城以北 提交于 2020-05-08 07:07:03
二叉查找树基础 二叉查找树(BST)满足这样的性质,或是一颗空树;或左子树节点值小于根节点值、右子树节点值大于根节点值,左右子树也分别满足这个性质。 利用这个性质,可以迭代(iterative)或递归(recursive)地用O(lgN)的时间复杂度在二叉查找树中进行值查找。 相关LeetCode题: 700. Search in a Binary Search Tree 题解 701. Insert into a Binary Search Tree 题解 450. Delete Node in a BST 题解 776. Split BST 题解 二叉查找树与有序序列 由性质可知,如果按中序(inorder)遍历二叉查找树,我们将得到递增序列;反过来,如果中序遍历的结果不是递增序列,则所遍历树不是二叉查找树。以下框架适用于多数需要中序遍历二叉树的场景: // 98. Validate Binary Search Tree bool isValidBST(TreeNode* root) { stack <TreeNode*> st; TreeNode * prv= NULL; while (root!=NULL||! st.empty()){ while (root!= NULL){ st.push(root); root =root-> left; } root = st

springboot+thymeleaf处理带搜索条件的分页问题解决思路

半腔热情 提交于 2020-05-08 05:17:21
一开始写项目的时候,没用ajax,导致做搜索分页功能的时候废了好大的劲,在这里分享一下处理这个问题的思路。 框架用的springboot,通过thymeleaf模板和前端交互,没有使用ajax,所以数据都是在域对象放的。分页用的springdatajpa的分页,他个其他的分页工具大同小异,优点在于不用在引入新的依赖,直接通过查询得到的就是Page对象,缺点就是springdatajpa自带的分页工具其起始页是从0开始的,这一点比较恶心,哈哈。 主要思路就是把搜索条件和分页的请求地址都在域中定义,然后再js方法中得到这些信息,发送请求的时候调用js方法,拼接带搜索条件的参数。 --page分页-- 代码写的啰嗦,抽时间优化一下 <div class = " box-footer " th:fragment= " page " xmlns:th= " http://www.thymeleaf.org " > <div class = " modal-footer no-margin-top " > <div class = " pull-left " > <div class = " form-group form-inline " > 总共 <span th:text= " ${page.totalPages} " ></span> 页,共<span th:text= " $

TCP的三次握手过程与四次挥手

故事扮演 提交于 2020-05-08 04:40:28
TCP 握手协议 在 TCP/IP协议 中, TCP协议 提供可靠的连接服务,采用三次握手建立一个连接. 第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确认; SYN:同步序列编号(Synchronize Sequence Numbers) 第二次握手:服务器收到syn包,必须确认客户的SYN(ack=j+1),同时自己也发送一个SYN包(syn=k),即SYN+ACK包,此时服务器进入 SYN_RECV 状态; 第三次握手:客户端收到服务器的SYN+ACK包,向服务器发送确认包ACK(ack=k+1),此包发送完毕,客户端和服务器进入ESTABLISHED状态,完成三次握手. 完成三次握手,客户端与服务器开始传送数据 A与B建立TCP连接时:首先A向B发SYN(同步请求),然后B回复SYN+ACK(同步请求应答),最后A回复ACK确认,这样TCP的一次连接(三次握手)的过程就建立了! 一、TCP报文格式 TCP/IP协议的详细信息参看《TCP/IP协议详解》三卷本。下面是TCP报文格式图: 图1 TCP报文格式 上图中有几个字段需要重点介绍下: (1)序号:Seq序号,占32位,用来标识从TCP源端向目的端发送的字节流,发起方发送数据时对此进行标记。 (2)确认序号:Ack序号,占32位,只有ACK标志位为1时

Objective-C Loops

余生颓废 提交于 2020-05-08 03:26:16
  There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.   Programming languages provide various control structures that allow for more complicated execution paths.   A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages:   Objective-C programming language provides the following types of loop to

Linux 常用命令不间断更新

狂风中的少年 提交于 2020-05-08 02:09:40
前提:Linux 命令 大小写敏感 1、 mkdir   make directory(ies)  若指定目录不存在则创建目录   -p, --parents no error if existing, make parent directories as needed 2、 ls   list  列出有关文件的信息(默认为当前目录)    -a, --all do not ignore entries starting with .   -d, --directory list directory entries instead of contents, and do not dereference symbolic links   -F, --classify append indicator (one of */=>@|) to entries     --full-time like -l --time-style=full-iso   -h, --human-readable with -l, print sizes in human readable format (e.g., 1K 234M 2G)   -i, --inode print the index number of each file   -l use a long listing format   

oracle学习笔记(一) oracle 体系结构简单介绍以及创建表空间和用户

喜欢而已 提交于 2020-05-07 20:16:22
体系结构 oracle数据服务器由oracle数据库和实例组成 实例由后台进程和内存结构组成 内存结构由共享池,数据缓冲区,日志缓存区 Oracle数据库是通过表空间来存储物理表的, 一个数据库实例可以有N个表空间,一个表空间下可以有N张表 。 使用数据库 先创建表空间,再创建数据库用户同时为用户分配表空间。 这样以后用这个新用户登录到Oracle时,所有这个用户创建的东西(表,视图..)都会存放在创建用户时分配给他的表空间里。 PS:以下的使用都需要sysdba管理员权限,可以在命令窗口或者是SQL窗口执行 1. 创建一个表空间 create tablespace $tablename$ datafile ‘%path%/*.dbf’ size 10M autoextend on/off --是否自动增长 --删除表空间 如果包含中括号,就是删除文件和内容 drop tablespace $tablespacename$ [including contents and datafile] 2. 创建一个用户,为用户分配表空间 create user $username$ identified by $password$ [default tablespace $tablespacename$] --表空间,默认分配user表空间 [temporary tablespace

sqlplus oracle 创建用户,授权,分配表空间

纵饮孤独 提交于 2020-05-07 20:16:02
1、 使用sqlplus 登陆system 先设置本地字符集: export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"; sqlplus system/0P-0P-0P-@192.168.1.66:1521/orcl sqlplus usr1/usr1@192.168.1.66:1521/orcl sqlplus usr2/usr2@192.168.1.66:1521/orcl 2、创建新用户 create user usrName identified by usrPasswd; create user usr1 identified by usr1; create user usr2 identified by usr2; create user usr3 identified by usr3; create user usr4 identified by usr4; create user usr5 identified by usr5; create user usr6 identified by usr6; 修改密码: alter user usrName identified by newPasswd; 3、查看所有用户所在表空间 select username,default_tablespace from dba_users;

oracel存储过程编写 以及plsql存储过程的debug

时间秒杀一切 提交于 2020-05-07 20:15:43
1、语法:   create or replace procedure messagebackup_createTable //此处存储过程名称不能超过30个字符 as tableName varchar2(100); //声明变量 tableCount Number;   thisYearMonth; begin   thisYearMonth:=TO_CHAR(sysdate,'yyyyMM'); //给变量赋值使用 :=   tableName:='MESSAGEBACKUP_'||thisYearMonth; //oracle大小写敏感,尽量使用大写;使用变量连接是使用符号 ||变量   select count(1) into tableCount from user_tables where table_name = tableName; //如果上一行tableName的赋值使用的是小写,这块会出错,明明已经建好了这个表但是查询的时候还是0,缺又不能重新创建; 判断当前用户下是否有要创建的表,并将数量赋值给tableCount,select count(1) into tableCount from user_tables where table_name = tableName;   if tableCount=0 then   execute immediate