算法
文章平均质量分 73
liliangnike
这个作者很懒,什么都没留下…
展开
-
Leetcode. 797. All Paths From Source to Target - 深度优先搜索(DFS)
对于自己掌握的不是很熟练的算法,完成题目之后,总结是十分必要的,以后复习起来很方便。1. 深度优先搜索算法(1)深度优先搜索算法是用来遍历图中的节点的;(2)一般从初始节点开始,逐步深入遍历各个节点,直到找到目标节点或者没有子节点的节点;(3)算法常用的数据结构是堆栈。简单地说,(1)一直走到底(2)栈,入栈,出栈2. 题目算法描述Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find al原创 2021-03-15 11:20:57 · 270 阅读 · 0 评论 -
Leecode - 1038. Binary Search Tree to Greater Sum Tree
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.As a reminder, a binary search tree is a tree that原创 2021-02-20 13:17:50 · 103 阅读 · 0 评论 -
Leetcode 807. Max Increase to Keep City Skyline
允许自己偷个懒吧,不想翻译题目了。(英语不好的不要骂我,哈哈)1. 算法描述In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the height of any number of buildings, by any amount (the amounts can be different fo原创 2020-11-24 14:52:03 · 121 阅读 · 0 评论 -
LeetCode 1329. Sort the Matrix Diagonally
1. 算法描述Given a m * n matrix mat of integers, sort it diagonally in ascending order from the top-left to the bottom-right then return the sorted array.给定 m * n 的整型矩阵mat, 按照左上到右下的顺序,升序排列对接线元素。举例:Input: mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]Output: [[1,1原创 2020-06-30 14:10:15 · 3613 阅读 · 0 评论 -
Leetcode - 541. Reverse String II
1. 算法描述给定一个字符串和一个整数k, 从字符串首字符开始,每2k个字符,反转前面k个字符。(1)如果字符串长度小于k, 则反转所有字符串;(2)如果字符串长度小于2k并且大于或等于k,则反转前面k个字符,剩余字符保持原来顺序。例如:Input: s = “abcdefg”, k = 2Output: “bacdfeg”2. 思想分析(1)如果s.length() >= 2k, reverse前面k个字符串。同时,将前2k个字符,累加到结果字符串;后2k个字符更新为s, 用来进行原创 2020-05-26 19:50:30 · 121 阅读 · 0 评论 -
Leetcode - 290. Word Pattern算法
1. 算法描述给定匹配格式,判断字符串是否符合格式。单词字符串需要完全符合给定的匹配格式,格式字符串和单词字符串有双射关系。Example 1:Input: pattern = “abba”, str = “dog cat cat dog”Output: trueExample 2:Input:pattern = “abba”, str = “dog cat cat fish”Output: falseExample 3:Input: pattern = “aaaa”, str = “d原创 2020-05-19 14:05:41 · 208 阅读 · 0 评论 -
Leetcode - Add Strings算法
1. 算法描述给定两个字符串,求取两者之和。(1)The length of both num1 and num2 is < 5100.(2)Both num1 and num2 contains only digits 0-9.(3)Both num1 and num2 does not contain any leading zero.(4)You must not use any built-in BigInteger library or convert the inputs to原创 2020-05-15 14:33:20 · 165 阅读 · 0 评论 -
Leecode - Excel Sheet Column Title/Excel Sheet Column Number算法总结
1. 给定电子表格title, C++算法实现获取对应的列数(1)题目介绍给出电子表格的title标识,找到对应的列数。举例:A -> 1B -> 2C -> 3…Z -> 26AA -> 27AB -> 28…ZY -> 701ZZ -> 702(2)原理分析该算法其实就是考察“26进制”转化为十进制,原理和二进制类似...原创 2020-05-08 11:33:26 · 199 阅读 · 0 评论 -
Leetcode - Happy Number算法总结
Happy Number算法submit了好几次,才最终测试通过,总结一下。1. Happy Number定义给定一个整数,将每一位数字的平方加起来,得出来一个和,继续将这个和的每一位数字的平方加起来,不断循环,如果最终的和是1的话,那么该整数即为Happy Number.举例:Input: 19Output: trueExplanation:12 + 92 = 8282 + 22...原创 2020-05-07 11:25:40 · 382 阅读 · 0 评论 -
爬梯子算法 - 斐波那契数列
1. 斐波那契数列 (Fibonacci Sequence)斐波那契数列,又称为黄金分割数列,是数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖引入,所以也称为兔子算法,是指这样的数列:1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, …这个数列从第三项开始, 每一项等于前面两项之和。...原创 2020-04-07 11:07:15 · 1302 阅读 · 0 评论 -
给定数字排数,构建杨辉三角(Pascal's Triangle) Vector
杨辉三角在大学C语言程序设计教程中出现过,是比较重要的一个例子,只不过上学的时候,不但听不懂而且也不知道其中的乐趣。没有接触过的朋友,可以自行google一下。下图就是杨辉三角数字组合:Leecode上有个算法题目,是给定数字的排数,构建杨辉三角,并且返回数字组合的vector.例如,算法 input: 5结果:[[1],[1,1],[1,2,1],[1,3,3,1],[1,4...原创 2020-03-05 13:27:29 · 221 阅读 · 0 评论