伪程序员的世界

Debug myself and debug the world!


  • 首页

  • 归档

  • 分类

  • 标签

  • 搜索

算法期中练习——1004. 拓扑序

发表于 2018-01-06 | 分类于 算法 , 2017算法期中考
字数统计: 3.8k | 阅读时长≈ 0:04

算法期中练习——1004. 拓扑序

Description:

在图论中,拓扑序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列. 且该序列必须满足下面两个条件:

  1. 每个顶点出现且只出现一次.
  2. 若存在一条从顶点 A 到顶点 B 的路径,那么在序列中顶点 A 出现在顶点 B 的前面.
    对于一个含有n个节点的有向无环图(节点编号0到n-1),输出它的一个拓扑序.
    图的节点数和边数均不多于100000,保证输入的图是一个无环图.
    阅读全文 »

算法期中练习——1003. 最近的0

发表于 2018-01-06 | 分类于 算法 , 2017算法期中考
字数统计: 3.3k | 阅读时长≈ 0:03

算法期中练习——1003. 最近的0

Description:

输入一个N*M的01矩阵A,对矩阵的每个位置,求至少经过多少步可以到达一个0. 每一步可以往上下左右走一格

阅读全文 »

算法期中练习——1002. 合并二叉树

发表于 2018-01-05 | 分类于 算法 , 2017算法期中考
字数统计: 2k | 阅读时长≈ 0:02

算法期中练习——1002. 合并二叉树

Description:

输入两个二叉树T1和T2,要求对T1和T2进行合并. 合并是指将二叉树同一位置节点上的数求和,作为合并后二叉树相应位置节点的数值. 如果某个位置上只有一个二叉树有节点,则合并后的二叉树对应位置上的节点上的数值就等于这个节点上的数值.

阅读全文 »

算法期中练习——1001. 最小差

发表于 2018-01-05 | 分类于 算法 , 2017算法期中考
字数统计: 1.4k | 阅读时长≈ 0:01

算法期中练习——1001. 最小差

Description:

对于一个整数数列A[0], A[1], …, A[N-1],要求在其中找两个数,使得它们的差的绝对值最小.
2 <= N <= 100, -1000 <= A[i] <= 1000.

阅读全文 »

算法期中练习——1000.分组

发表于 2018-01-05 | 分类于 算法 , 2017算法期中考
字数统计: 1.8k | 阅读时长≈ 0:02

算法期中练习——1000.分组

Description:

对于一个整数数列A[0], A[1], …, A[N-1]进行分组,要求每组1到2个数,并且同组之和不能大于w. 求最少可以分成多少组.
1 <= N <= 100000, 1 <= A[i] <= w <= 1000000000.

阅读全文 »

LeetCode 278. First Bad Version

发表于 2018-01-01 | 分类于 算法 , LeetCode
字数统计: 1.5k | 阅读时长≈ 0:02

LeetCode 278. First Bad Version

Description:

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

Suppose you have n versions [1, 2, …, n] and you want to find out the first bad one, which causes all the following ones to be bad.

You are given an API bool isBadVersion(version) which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

阅读全文 »

LeetCode 69. Sqrt(x)

发表于 2018-01-01 | 分类于 算法 , LeetCode
字数统计: 1.4k | 阅读时长≈ 0:01

LeetCode 69. Sqrt(x)

Description:

Implement int sqrt(int x).

Compute and return the square root of x.

x is guaranteed to be a non-negative integer.

阅读全文 »

LeetCode 198. House Robber

发表于 2017-12-25 | 分类于 算法 , LeetCode
字数统计: 1.9k | 阅读时长≈ 0:02

LeetCode 198. House Robber

Description:

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

阅读全文 »

LeetCode 746. Min Cost Climbing Stairs

发表于 2017-12-25 | 分类于 算法 , LeetCode
字数统计: 1.7k | 阅读时长≈ 0:02

LeetCode 746. Min Cost Climbing Stairs

Description:

On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).

Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.

阅读全文 »

LeetCode 70. Climbing Stairs

发表于 2017-12-25 | 分类于 算法 , LeetCode
字数统计: 1.5k | 阅读时长≈ 0:01

LeetCode 70. Climbing Stairs

Description:

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

阅读全文 »
1…567…11
linjiafengyang

linjiafengyang

Debug myself and debug the world!

106 日志
7 分类
3 标签
GitHub CSDN
© 2019 linjiafengyang | 394k | 6:34