
刷题
yqf113
这个作者很懒,什么都没留下…
展开
-
剑指offer第40题:最小的K个数
输入N个整数,寻找其中最小的k个数。方法1:利用Partition函数,找到位于第k-1坐标的数,则它左边的数以及它自己就是要返回的k个数。class Solution {public: void swap(int &fir, int &sec) { int temp = fir; fir = sec; sec = temp; } int getP...原创 2019-05-28 17:56:45 · 130 阅读 · 0 评论 -
剑指offer28 对称的二叉树
给定一个二叉树,判断该二叉树是不是对称的。1.递归方法class Solution {public: bool isSymmetrical(TreeNode* pRoot) { return isSymmetrical(pRoot,pRoot); } bool isSymmetrical(TreeNode* pRoot1,TreeNode...原创 2019-06-23 21:12:01 · 289 阅读 · 0 评论 -
剑指offer 32.从上到下打印二叉树
2.分行打印class Solution {public: vector<vector<int> > Print(TreeNode* pRoot) { vector<vector<int>> res; if (pRoot == nullptr) return res; deque<TreeNode*> d; ...原创 2019-06-24 00:12:35 · 176 阅读 · 0 评论 -
算法题:求一个数的三次方根
方法1:二分迭代法#include <cstdio>#include <iostream>#include <algorithm>#define eps 1e-8using namespace std;double n;double fun(double mid){return mid*mid*mid<n?1:0;}int m...转载 2019-08-22 12:41:21 · 4036 阅读 · 0 评论