
all accept弱鸡刷刷题
文章平均质量分 66
写代码的柯长
Do the impossible.
See the invisible.
Raw! Raw!
Fight the power.
展开
-
leetcode-279. Perfect Squares
leetcode-279. Perfect Squares问题描述如下: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 becaus翻译 2017-08-24 20:17:51 · 420 阅读 · 0 评论 -
1101. Quick Sort
这道题想找到一组数据中满足,左边的数字都小于它,右边的数字都大于它的数字。 最暴力的方法n^2会超时 这道题的Quick Sort实际上已经提示我们了,这道题的重点在于发现符合题目条件的数字在sort之后的位置是相同的,这一点回想quick sort过程就很容易验证,并且保证数组中的数字要大于前面数字的最大值,就会满足题意,具体代码如下:#include<iostream> #include<v原创 2018-05-06 14:12:56 · 256 阅读 · 0 评论 -
1103. Integer Factorization
题目的大体意思就是,给出N,k,p三个数字 找出满足N=n_1^P+…n_k^P的所有n的值,并且在所有方法中找到n_1+…+n_k最大的值,如果大小相同,就选择字典序最大的一组数组。 这道题肯定是要通过搜索去寻找最合适的组合,明显是dfs(有点贪心的意思在里面) 首先,先将index^p #include<iostream> #include<cstdio> ...原创 2018-05-06 14:04:20 · 387 阅读 · 0 评论 -
1123. Is It a Complete AVL Tree(AVL树旋转、判断完全二叉树)
Is It a Complete AVL Tree (30) An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ b原创 2018-03-08 17:14:23 · 662 阅读 · 0 评论 -
记录题目中遇到的坑
1.尽量用scanf和printf,不用cin和cout(太慢了),除非用 std::ios::sync_with_stdio(false) 取消同步 例题:http://poj.org/problem?id=1182(考察并查集,时间卡的很死) 2.高精度问题,看到问题中要输入1000个digits的数字表示高精度数字,如下描述: Each input file contains ...原创 2017-12-19 17:38:18 · 246 阅读 · 0 评论 -
从差分约束到最短路径(POJ 3169)
话不多说,先来看这么几个线性规划的约束方程: x1−x2⩽0x1−x5⩽−1x2−x5⩽1x3−x1⩽5x4−x1⩽4x4−x3⩽−1x5−x3⩽−3x5−x4⩽−3\begin{equation} x_1-x_2 \leqslant 0 \\ x_1-x_5 \leqslant -1 \\ x_2-x_5 \leqslant 1 \\ x_3-x_1 \leqslant 5 \\ x_4-x_1原创 2017-12-19 14:16:41 · 809 阅读 · 0 评论 -
leetcode105 && leetcode106 && PAT 1138. 二叉树的三种遍历的应用
俗话说的好“你先前跳过的坑,迟早都要再踩进去的” 昨天考的PAT的利用二叉树的前序和中序遍历得到后序遍历的第一个值。想起在leetcode上做过,却没做出来。特此,对二叉树的三种遍历做个复习。二叉树的三种遍历分别为:前序遍历(preorder),中序遍历(inorder),后序遍历(postorder),这三种遍历的区别直接体现在代码上,看如下三个代码:void preorder(TreeNode原创 2017-12-10 23:35:48 · 573 阅读 · 0 评论 -
1010. Radix (25)
题目描述: Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is “yes”, if 6 is a decimal number and 110 is a binary number.Now for any pair of positiv原创 2017-11-10 11:02:00 · 192 阅读 · 0 评论 -
leetcode222. Count Complete Tree Nodes
记录这道题的目的主要是想复习一下计算时间复杂度的方法。题目描述是这样的: Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibl原创 2017-10-20 16:55:36 · 347 阅读 · 0 评论 -
leetcode113. Path sum II
这道题是path sum I的升级版,通过这道题我发觉我竟然忘了树的一个重要定义。所以在这做一个记录: 题目描述如下: Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.For example: Given the below binary原创 2017-10-01 23:41:44 · 203 阅读 · 0 评论 -
leetcode102. Binary Tree Level Order Traversal & 103. Zigzag Level
这两道题同样是树的层级遍历。所以,特地将这两道题拿在一起说 先来说102: Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree [3,9,20,null原创 2017-10-01 23:22:13 · 228 阅读 · 0 评论 -
leetcode 225 & 232.Implement Stack using Queues & Implement Queue using Stacks
突然听人说起有同学做了某游戏公司的笔试题,遇到如何用栈实现队列,想起来自己在半年前做过用队列实现栈和用栈实现队列,现在回忆起来,只记得如果用栈实现队列,忘了用队列实现栈了,在此记录一下。 总所周知,栈是先进先出,队列是先进后出。 对于一个序列来说,一个序列进入队列之后,再出来,序列顺序不变。 在进入栈之后,再出来,序列顺序相反了。 无论是用栈实现队列,还是用队列实现栈,实际上考虑的都是如何将原创 2017-09-09 11:27:30 · 298 阅读 · 0 评论 -
leetcode309&121&122.Best Time to Buy and Sell Stock 问题
本次总结的是leetcode上著名的几个问题:Best Time to Buy and Sell Stock 1,2 Best Time to Buy and Shell Stock With Cooldown问题。问题的大概框架就是, 给你一个代表每天物品价格的数组,你可以买,卖商品,要求得到最大的收益。这里先来谈一下这个问题: Best Time to Buy and Sell Stoc原创 2017-09-11 22:26:21 · 292 阅读 · 0 评论 -
leetcode322 coin change & leetcode343 integer break
此次将动态规划专题里面的两个类型的题目统一做一个记录,这两道题都有一个共同的动态规划的特性,利用前面的最优解推出后面的最有解,空间复杂度为O(n),即都要运用到整个数组的数字。 先是leetcode322 coin change You are given coins of different denominations and a total amount of money amount. W原创 2017-09-24 17:33:17 · 285 阅读 · 0 评论 -
leetcode 304.Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). The above rectangle (with the red border)原创 2017-09-06 17:08:28 · 259 阅读 · 0 评论 -
leetcode 300.Longest Increasing Subsequence
题目描述: Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], th原创 2017-09-06 14:57:58 · 233 阅读 · 0 评论 -
332. Reconstruct Itinerary
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, th...原创 2018-10-25 19:25:49 · 389 阅读 · 0 评论