20180613更新 leetcode刷题
最近就是忙工作项目 工作间隙就刷了刷LEETCODE 所以没啥更新

// 1111111.cpp: 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <vector>
#include <queue> using namespace std; bool canFinish1(int numCourses, vector<vector<int>>& prerequisites) {
vector<vector<int> > graph(numCourses, vector<int>());
vector<int> in(numCourses, );
for (auto a : prerequisites) {
graph[a[]].push_back(a[]);
++in[a[]];
}
queue<int> q;
for (int i = ; i < numCourses; ++i) {
if (in[i] == ) q.push(i);
}
while (!q.empty()) {
int t = q.front();
q.pop();
for (auto a : graph[t]) {
--in[a];
if (in[a] == ) q.push(a);
}
}
for (int i = ; i < numCourses; ++i) {
if (in[i] != ) return false;
}
return true;
} //========================================================================== bool canFinishDFS(vector<vector<int> > &graph, vector<int> &visit, int i) {
if (visit[i] == -) return false;
if (visit[i] == ) return true;
visit[i] = -;
for (auto a : graph[i]) {
if (!canFinishDFS(graph, visit, a)) return false;
}
visit[i] = ;
return true;
} bool canFinish2(int numCourses, vector<vector<int> >& prerequisites) {
vector<vector<int> > graph(numCourses, vector<int>());
vector<int> visit(numCourses, );
for (auto a : prerequisites) {
graph[a[]].push_back(a[]);
}
for (int i = ; i < numCourses; ++i) {
if (!canFinishDFS(graph, visit, i)) return false;
}
return true;
} int main()
{
//测试数据
{
int i = ;
vector<vector<int> > v;
v.push_back(std::vector<int>{, });
v.push_back(std::vector<int>{ ,});
canFinish1(i , v);
}
//{
// int i = 2;
// vector<vector<int> > v;
// v.push_back(std::vector<int>{1, 0});
// v.push_back(std::vector<int>{0, 1});
//}
//{
// int i = 2;
// vector<vector<int> > v;
// v.push_back(std::vector<int>{1, 0});
//}
//{
// int i = 3;
// vector<vector<int> > v;
// v.push_back(std::vector<int>{1, 0});
// v.push_back(std::vector<int>{2, 0});
//} // {
// int i = 3;
// vector<vector<int> > v;
// v.push_back(std::vector<int>{1, 0});
// v.push_back(std::vector<int>{2, 0});
// }
//
// {
// int i = 3;
// vector<vector<int> > v;
// v.push_back(std::vector<int>{0, 1});
// v.push_back(std::vector<int>{1, 2});
// }
//
// {
// int i = 4;
// vector<vector<int> > v;
// v.push_back(std::vector<int>{0, 1});
// v.push_back(std::vector<int>{1, 2});
// v.push_back(std::vector<int>{2, 0});
// v.push_back(std::vector<int>{1, 3});
// }
//
// {
// int i = 4;
// vector<vector<int> > v;
// v.push_back(std::vector<int>{0, 1});
// v.push_back(std::vector<int>{1, 2});
// v.push_back(std::vector<int>{1, 3});
// } return ;
}
leetcode 207
20180613更新 leetcode刷题的更多相关文章
- LeetCode刷题专栏第一篇--思维导图&时间安排
昨天是元宵节,过完元宵节相当于这个年正式过完了.不知道大家有没有投入继续投入紧张的学习工作中.年前我想开一个Leetcode刷题专栏,于是发了一个投票想了解大家的需求征集意见.投票于2019年2月1日 ...
- LeetCode刷题总结之双指针法
Leetcode刷题总结 目前已经刷了50道题,从零开始刷题学到了很多精妙的解法和深刻的思想,因此想按方法对写过的题做一个总结 双指针法 双指针法有时也叫快慢指针,在数组里是用两个整型值代表下标,在链 ...
- LeetCode刷题总结-数组篇(上)
数组是算法中最常用的一种数据结构,也是面试中最常考的考点.在LeetCode题库中,标记为数组类型的习题到目前为止,已累计到了202题.然而,这202道习题并不是每道题只标记为数组一个考点,大部分习题 ...
- LeetCode刷题总结-数组篇(中)
本文接着上一篇文章<LeetCode刷题总结-数组篇(上)>,继续讲第二个常考问题:矩阵问题. 矩阵也可以称为二维数组.在LeetCode相关习题中,作者总结发现主要考点有:矩阵元素的遍历 ...
- LeetCode刷题总结-数组篇(下)
本期讲O(n)类型问题,共14题.3道简单题,9道中等题,2道困难题.数组篇共归纳总结了50题,本篇是数组篇的最后一篇.其他三个篇章可参考: LeetCode刷题总结-数组篇(上),子数组问题(共17 ...
- LeetCode刷题总结-树篇(上)
引子:刷题的过程可能是枯燥的,但程序员们的日常确不乏趣味.分享一则LeetCode上名为<打家劫舍 |||>题目的评论: 如有兴趣可以从此题为起点,去LeetCode开启刷题之 ...
- LeetCode刷题笔记和想法(C++)
主要用于记录在LeetCode刷题的过程中学习到的一些思想和自己的想法,希望通过leetcode提升自己的编程素养 :p 高效leetcode刷题小诀窍(这只是目前对我自己而言的小方法,之后会根据自己 ...
- LeetCode刷题模板(1):《我要打10个》之二分法
Author : 叨陪鲤 Email : vip_13031075266@163.com Date : 2021.01.23 Copyright : 未 ...
- leetcode刷题目录
leetcode刷题目录 1. 两数之和 2. 两数相加 3. 无重复字符的最长子串 4. 寻找两个有序数组的中位数 5. 最长回文子串 6. Z 字形变换 7. 整数反转 8. 字符串转换整数 (a ...
随机推荐
- Spring Boot Maven 打包 Jar
Maven pom.xml 必须包含 <packaging>jar</packaging> <build> <plugins> <plugin&g ...
- asp.net之发送邮件2
public void SendMail(string from, string to, List<string> cc, string subject, string body) { M ...
- 生产环境nginx上传文件报错413 Request Entity Too Large
修改nginx配置文件/etc/nginx/nginx.conf 在http{}中添加 client_max_body_size 100m; 意思是设置上传文件大小
- python模块 re模块与python中运用正则表达式的特点 模块知识详解
1.re模块和基础方法 2.在python中使用正则表达式的特点和问题 3.使用正则表达式的技巧 4.简单爬虫例子 一.re模块 模块引入; import re 相关知识: 1.查找: (1)find ...
- ORACLE 如何产生一个随机数
1.select dbms_random.string('x', 3) from dual ; x是类型,3是长度. /* opt可取值如下: 'u','U' : 大写字母 'l','L' ...
- Django2.1在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'
解决办法: a=models.ForeignKey('BookInfo',on_delete=models.CASCADE,) 即在外键值的后面加上 on_delete=models.CASCADE ...
- 100-days: Four
Title: Weekend 'catch-up sheep' is a lie catch-up n.补做:赶做 play catch-up 通过追赶,达到同样的水平或程度 catch-up sle ...
- HDU 4940 Destroy Transportation system(无源汇上下界网络流)
Problem Description Tom is a commander, his task is destroying his enemy’s transportation system. Le ...
- TZOJ 3709:Number Maze(广搜记录前驱)
描述 You are playing one game called "Number Maze". The map of an example is shown in the fo ...
- 关于django的操作(四)
1,关于form组件的写法 定义错误信息使用error_messages,自定义字段名称用lebal,自定义样式需要使用widget,比方说这个是一个什么样子的输入框,attr用于输入输入框的属性等 ...