![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
剑指offer刷题记录
好好学习_天天向上de
加油ヾ(◍°∇°◍)ノ゙
展开
-
剑指offer:用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型
C++版本:class Solution{public: void push(int node) { stack1.push(node); } int pop() { while(!stack1.empty()) { stack2.push(stack1.top()); ...原创 2019-06-14 10:55:28 · 401 阅读 · 0 评论 -
剑指offer:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。
题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。C++版本:#include <cmath>class Solution {public:...原创 2019-06-14 11:43:47 · 1586 阅读 · 1 评论 -
剑指offer:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)
C++ 版本:class Solution {public: int Fibonacci(int n) { int f=0,s=1; if (n==0)return 0; if(n==1)return 1; int result=n; int i; for (i=2;i<=n;i+...原创 2019-06-14 19:48:02 · 377 阅读 · 1 评论 -
剑指offer:
C++版本class Solution {public: int NumberOf1(int n) { int count=0; unsigned int flag=1; while(flag){ if (n & flag){ count++;...原创 2019-06-14 20:23:26 · 75 阅读 · 0 评论