
c++算法
Ares-T
You still have lots more to work on!!!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 42. Trapping Rain Water
第一次写博客,我这种水平的大学生程序猿为什么会想到要写博客这种东西呢,而且还要周更呢?没错,这是我们老师布置的作业。如果觉得我的博客写得有何不妥,请在下方留言,每周我会抽取幸运观众进行回复,谢谢大家。进入正题,这是我们算法老师布置的作业,每周我将在LeetCode上抽取幸运题进行解答,并编写题解在博客上。打开LeetCode,因为我之前尝试过一道难度为中等的题,觉得还行,所以这一次我直接找了一原创 2017-02-24 20:25:38 · 664 阅读 · 0 评论 -
算法作业8.9
这是一次期末作业,是使用规约来证明NP完全问题的,关于判定问题规约的定义大概意思就是可以使用一个多项式时间内的算法将问题1的实例装换问问题2的实例,,最后答案还是一致的,对于刚学完近世代数的我来说感觉就是在证明问题1和问题2是同构的,然后需要找到一个同构映射。而证明NP完全问题则是需要证明这个问题可以规约为一个已知的NP完全问题。下面还是先上题目吧。----------------------原创 2017-07-04 20:38:05 · 522 阅读 · 0 评论 -
leetCode 79. Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically nei...原创 2018-03-14 18:29:48 · 321 阅读 · 0 评论 -
leetcode 31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible ord...原创 2018-03-01 15:17:24 · 243 阅读 · 0 评论 -
leetcode Generate Parentheses
题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())",...原创 2018-02-24 19:45:54 · 262 阅读 · 0 评论 -
leetcode 50. Pow(x, n)
题目如下:Implement pow(x, n).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100大概意思就是让我们写一个求幂的函数,由之前做密码时得出的经验,一般涉及到幂的运算都是使用快速幂的方法,我也动手写了,但是测试点到倒数第四个就挂了,测试点如下:n的取值...原创 2018-02-25 22:59:19 · 252 阅读 · 0 评论 -
leetcode 98. Validate Binary Search Tree/99. Recover Binary Search Tree
98:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The rig...原创 2018-04-02 17:19:45 · 236 阅读 · 0 评论 -
leetcode:124. Binary Tree Maximum Path Sum
Given a non-empty binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections...原创 2018-06-05 20:37:18 · 269 阅读 · 0 评论 -
leetcode145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [3,2,1]题目的要求说白了就是要我们求一棵树的后序遍历。那就顺便复习以下吧。前序遍历的规则:(1)访问根节点(2)前序...原创 2018-06-07 17:13:34 · 321 阅读 · 0 评论 -
128. Longest Consecutive Sequence
严格来说这道题算是诈胡吧,而且理论上来说难度也没达到hard,直接上题目吧:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100...原创 2018-06-02 14:24:17 · 242 阅读 · 0 评论 -
LRU Cache
题目如下,没有想到大二学的操作系统还能用上,先解释一下什么叫LRU吧。LRU是Least Recently Used的缩写,即最近最少使用,常用于页面置换算法,是为虚拟页式存储管理服务的。LRU算法的提出,是基于这样一个事实:在前面几条指令中使用频繁的页面很可能在后面的几条指令中频繁使用。反过来说,已经很久没有使用的页面很可能在未来较长的一段时间内不会被用到。这个,就是著名的局部性原理——比内存速...原创 2018-06-10 17:40:12 · 836 阅读 · 0 评论 -
LeetCode hard 335. Self Crossing
因为老师这周在讲比较形而上的NP问题,所以就让我们随便选题了,果断我就真随便选了,看了tag后才发现这是一道数学题,还是一道几何题,好吧,没这么严重,估计小学生都能想出一点东西来,直接上题吧-----------------------题目--------------------You are given an array x of n positive numbers. You st原创 2017-06-10 11:24:00 · 464 阅读 · 0 评论 -
Best Time to Buy and Sell Stock系列问题题解
本来只是想做一下第四个题,奈何里面的细节有些地方不懂,只能从第一题开始做,心累啊~-------------------------第一题题目------------------------Say you have an array for which the ith element is the price of a given stock on dayi.If you we原创 2017-06-04 13:25:24 · 458 阅读 · 0 评论 -
LeetCode hard 45. Jump Game II
这道题虽然在难度上是hard,但是想要做出来还是挺容易的,可能是我投机取巧了?它的tag写的是greedy,但是我用的是动态规划,不知道算不算是违规了。----------------------题目---------------------------Given an array of non-negative integers, you are initially positioned原创 2017-06-18 09:51:28 · 437 阅读 · 0 评论 -
LeetCode 312. Burst Balloons
这周老师布置的题的主题为divide and conquer,其实发现LeetCode上面这方面的题不是很多,为了拿高分我把所有难度为hard的题都看了一下,最后我选择了一道通过率最高的题(毕竟柿子还是得挑软的捏),也就是今天这一道Burst Balloons。首先我们来看一下题目吧。Given n balloons, indexed from 0 to n-1. Each balloon原创 2017-03-05 09:07:38 · 555 阅读 · 0 评论 -
LeetCode 329. Longest Increasing Path in a Matrix
这次我们的主题是深度优先搜索,在LeetCode上按照惯例找了一道难度为hard但通过率最高的题,但是我发现最高的那道题情况有点复杂,所以我觉得选择了这一道通过率次高的 Longest Increasing Path in a Matrix 先上题目吧--------------------------------这是题目-----------------------------Giv原创 2017-03-19 09:26:03 · 1475 阅读 · 0 评论 -
LeetCode 315. Count of Smaller Numbers After Self
又到一周更新时,这次的题目依旧来自LeetCode,由于这周老师还是讲的divide and conquer,按照以往的惯例,我从难度为hard的题目中挑选了一道通过率第二高的题,因为第一高的题上一次做了,所以这次的题目是315号题 Count of Smaller Numbers After Self,下面是题目介绍:---------------------------------题目--原创 2017-03-12 15:11:23 · 998 阅读 · 0 评论 -
LeetCode 540. Single Element in a Sorted Array
这次随便找了一道题写,之前找了一道题,写了一个上午都没写出来就放弃了,一气之下就直接随便选了一道题写。话不多少之前看题吧。---------------------这是题目-----------------------------Given a sorted array consisting of only integers where every element appears twic原创 2017-04-09 19:42:58 · 996 阅读 · 0 评论 -
LeetCode 513. Find Bottom Left Tree Value
此次题解的主题是BFS,也就是宽度优先搜索,如果不清楚概念请移步某百科,粗略解释一下吧,假设有一棵树(希望你们懂我说的树是什么树),我们从root开始,将所有与root这个点相连的点加入到一个队列中,队列这个数据结构是实现bfs的核心,这样我们就已经遍历完这棵树的第一层了,接下来就是第二层了,我们从这个第一层队列中取出第一个点,把它当成root,重复上面的操作,然后将这个root从队列弄出去,直到原创 2017-04-02 13:40:58 · 608 阅读 · 0 评论 -
LeetCode 413. Arithmetic Slices
这周老师讲了动态规划,然后我在tag为dp的题库中找到了这道题,难度为medium,然而比较尴尬的事情发生了,先上题吧-------------------下面是题目--------------------A sequence of number is called arithmetic if it consists of at least three elements and if原创 2017-05-01 10:10:36 · 692 阅读 · 0 评论 -
LeetCode 502. IPO
这周老师讲解了一下贪心算法(greedy),我科对贪心的解释是贪心算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择。也就是说,不从整体最优上加以考虑,他所做出的是在某种意义上的局部最优解。贪心算法不是对所有问题都能得到整体最优解,关键是贪心策略的选择,选择的贪心策略必须具备无后效性,即某个状态以前的过程不会影响以后的状态,只与当前状态有关。大概就是这样,按照惯例原创 2017-04-16 09:26:11 · 1460 阅读 · 0 评论 -
动态规划 hard LeetCode 354. Russian Doll Envelopes
这周依旧是动态规划,老师说动态规划的内容很多,有很多变种,所以讲了很久,前几天看到一篇文章说动态规划不是一种算法而是一种思想,觉得挺有道理的,毕竟它不像其他算法那样有一个固定的方法,但是某种程度上来说也是有的,嗯,进入正题吧,不纠结这个问题了。下面看一看这周的题吧,难度为hard,题目如下:--------------------------题目------------------------原创 2017-05-14 13:26:24 · 497 阅读 · 0 评论 -
LeetCode dynamic programming 72. Edit Distance
这周老师继续上周讲了动态规划,也提到了这个所谓的编辑距离,刚好在LeetCode上看到了就顺便练练手吧,没想到难度还是hard,不过让我自己想我估计肯定是想不出来的=.=具体的算法细则以及证明可以看一下百度百科,我们老师上课讲的挺复杂了,画了好大一个图才讲完,虽然觉得没必要来写题解,但威力完成任务还是按照老规矩走一走流程吧。有兴趣的可以参考我们算法课的教材《算法导论》第162页,上面对这个讲得原创 2017-05-06 20:20:37 · 469 阅读 · 0 评论 -
动态规划 hard LeetCode 403. Frog Jump
dynamic programming again!可能是这个问题太复杂了吧,老师讲了好几周了,然而我却还是不能很好的理解这中思想,感觉就是遍历。回到正题,这次的选题比较果断,选定后就没有改了,死磕,然后我懵了。下面看题目吧。--------------------下面是题目---------------------------A frog is crossing a river. T原创 2017-05-21 12:57:44 · 1070 阅读 · 0 评论 -
Leetcode 154. Find Minimum in Rotated Sorted Array II
题目如下:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.The array may...原创 2018-07-31 16:58:46 · 305 阅读 · 0 评论