当前位置:网站首页>Sword finger offer II 115. reconstruction sequence
Sword finger offer II 115. reconstruction sequence
2022-07-23 22:29:00 【anieoo】
Original link : The finger of the sword Offer II 115. Reconstruction sequence
solution:
Topology sorting application
const int N=100010;
int h[N],e[N],ne[N];
int n,m;
int d[N];//d Indicates the penetration of the point
class Solution {
public:
int idx = 0;
void add(int a,int b) {
e[idx] = b;
ne[idx] = h[a];
h[a] = idx++;
}
bool sequenceReconstruction(vector<int>& nums, vector<vector<int>>& sequences) {
memset(h, -1, sizeof(h));
memset(e, 0, sizeof(e));
memset(ne, 0, sizeof(ne));
memset(d, 0, sizeof(d));
int n = nums.size();
for (const auto& s: sequences) {
for (int i = 1; i < s.size(); ++i) {
add(s[i - 1], s[i]);
d[s[i]]++;
}
}
queue<int> que; // The queue used for topological sorting
// Set all entries to 0 To join the queue
for(int i = 0;i < n;i++) {
if(!d[nums[i]]) {
que.push(nums[i]);
}
}
int index = 0; // Topological sequence sum nums Compare
while(!que.empty()) {
if(que.size() > 1) return false; // The degree of 0 The number of is greater than 1 return false
int t = que.front();
if(t != nums[index++]) return false;
que.pop();
for(int i = h[t];i != -1;i = ne[i]) {
int j = e[i];
d[j]--;// Delete point t Point of reference j The edge of
if(d[j]==0) {
que.push(j);
}// If you order j Your penetration is zero , Just point j The team
}
}
return true;
}
};边栏推荐
- Matlab小波工具箱导入信号出错(doesn‘t contain one dimensional Singal)
- How can I open an account to buy financial products with a 6% income?
- JMeter performance comprehensive practice - sign in and batch sign in
- About synchronizing data from computer to mobile
- 糖尿病遗传风险检测挑战赛进阶
- 10道面试基础笔试题,你能对几题?
- 如何徹底强制殺死後臺無關進程?
- DeFi项目的盈利逻辑 2021-04-26
- ospf终极实验——学会ospf世纪模板例题
- U++ learning notes tsubclassof()
猜你喜欢

02.网页结构相关知识补充

巴菲特股东大会的启示 2021-05-06

Investment suggestions for overseas senior players (3) 2021-05-04

Multithreading problem: why should we not use multithreading to read and write the same socket connection?
![[golang learning notes] is parameter transfer in go language value transfer or reference transfer](/img/79/57b28d0e6501132c347f7e7c0516b3.png)
[golang learning notes] is parameter transfer in go language value transfer or reference transfer

Altium Designer - schematic diagram of Arduino uno & PCB diagram (self-made Arduino board)

Inspiration from Buffett's shareholders' meeting 2021-05-06

D2admin framework is basically used

达梦数据库tools包中的工具(操作达梦数据库)

Introduction and project development of MVVM and mvvmlight (I)
随机推荐
小说里的编程 【连载之十九】元宇宙里月亮弯弯
LeetCode高频题53. 最大子数组和,具有最大和的连续子数组,返回其最大和
zk 是如何解决脑裂问题的
【golang学习笔记】并发基础
How can I open an account to buy financial products with a 6% income?
Programmation JDBC pour MySQL
Relevant interfaces of [asp.net core] option mode
[C language] address book (static version)
"Morning reading" if you were in my position, what would you do? How do we do it,
MySQL index transaction
Cookies and sessions
初探POC编写
El select drop-down box multi selection remote search anti display
Leetcode high frequency question 62. different paths: how many paths does the robot have from the upper left corner to the lower right corner? Pure probability permutation and combination problem, not
Introduction and project development of MVVM and mvvmlight (I)
思源笔记的字体比其他的编辑器(Atom,VSC,sublime)内字体渲染更细更淡
淘宝助理停用,用大淘营导入数据包上传宝贝提示“主图为必填项,不能为空”是什么原因?如何解决?
Array - 704. Binary search
软件测试工作内容太简单怎么办?
Altium designer—Arduino UNO原理图&PCB图(自制Arduino板)