自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(21)
  • 收藏
  • 关注

原创 剑指offer——青蛙跳台阶(初级版+变态版)

剑指offer——青蛙跳台阶 1.初级版 题目描述: 一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。 题目分析: 递归,每次如果刚好跳到终点,种数+1 如果越过了终点,return 如果还没到终点,继续跳一格和两格; AC代码: class Solution { public: int jumpFloor(int nu...

2019-03-26 14:09:07 362

原创 LeetCode——triangle 数塔问题

LeetCode——triangle 薯塔 数塔问题 题目描述: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following tria...

2019-06-16 16:32:24 627

原创 LeetCode ——single-number 从一个数列中找出只出现一次的数,不借助额外内存,时间复杂度O(n)

LeetCode ——single-number 题目描述: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you imp...

2019-06-14 20:19:28 352

原创 LeetCode——merge-two-sorted-lists合并两个有序链表

LeetCode——merge-two-sorted-lists合并两个有序链表 题目描述: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 把两个有序链表合并成一...

2019-06-11 17:01:41 200

原创 LeetCode——word break 字符串切割

LeetCode——word break 字符串切割 题目描述: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s ...

2019-04-10 22:14:17 259

原创 LeetCode——linked-list-cycle-ii 判断链表是否有环,如果有,返回环的入口

LeetCode——linked-list-cycle-ii 判断链表是否有环,如果有,返回环的入口 题目描述: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up: Can you solve it without using extra ...

2019-04-10 17:21:10 231

原创 LeetCode——symmetric tree 对称树

LeetCode——symmetric tree 对称树 题目描述:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). Note: Bonus points if you could solve it both recursively and iterative...

2019-04-08 15:49:09 264

原创 LeetCode——same tree 判断两棵树是否相同

LeetCode——same tree 判断两棵树是否相同 题目描述: Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes h...

2019-04-08 11:51:59 206

原创 LeetCode——minimum-depth-of-binary-tree 二叉树的最小深度

LeetCode——minimum-depth-of-binary-tree 二叉树的最小深度 题目描述: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the neares...

2019-04-07 15:05:36 201

原创 剑指offer——最大连续子序列和

剑指offer——最大连续子序列和 题目描述: HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学。今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决。但是,如果向量中包含负数,是否应该包含某个负数,并期望旁边的正数会弥补它呢?例如:{6,-3,-2,7,-15,1,2,2},连续子向量的最大和为8(从第0个开始,到第3个为止...

2019-04-03 16:27:46 290

原创 剑指offer——二叉树的镜像

剑指offer——二叉树的镜像 题目描述: 操作给定的二叉树,将其变换为源二叉树的镜像。 题目分析: 按照某种顺序遍历二叉树,交换其左右结点。 推荐前序和后序。 中序容易出错。 如果中序,对一个结点的操作顺序是: 将该结点的左子树镜像->交换左右结点->将该结点的右子树镜像 Bug来了,交换后访问的右子树其实是以前的左子树,之前把左子树镜像了,现在又镜像一遍,其实这棵树没变。。。。。。...

2019-03-26 18:44:50 159

原创 剑指offer——反转链表

剑指offer——反转链表 题目描述: 输入一个链表,反转链表后,输出新链表的表头。 题目分析: 先存入数组,再反转数组; AC代码: /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ...

2019-03-26 17:33:34 169

原创 剑指offer——链表中倒数第k个结点(队列实现)

剑指offer——链表中倒数第k个结点 题目描述 : 输入一个链表,输出该链表中倒数第k个结点。 题目分析: 做一个长度为k的滑动窗口,当访问链表结束时,输出窗口第一个; 用队列做这个窗口。 AC代码: /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { ...

2019-03-26 16:21:12 325

原创 剑指offer——求整数幂

剑指offer——求整数幂 题目描述: 给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。 题目分析: 直接pow 居然也可以 不用库函数的方法: 1.一次次累乘,复杂度O(n) 2.快速幂,复杂度O(log n) 3.递归,递归常产生多次重复计算 下面的代码用快速幂方法 AC代码: class Solution { public: d...

2019-03-26 15:25:51 278

原创 剑指offer——矩形覆盖

剑指offer——矩形覆盖 题目描述: 我们可以用21的小矩形横着或者竖着去覆盖更大的矩形。请问用n个21的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 题目分析: 如图,其实就是个斐波拉契数列 AC代码: class Solution { public: int rectCover(int number) { map<int,i...

2019-03-26 14:28:56 212

原创 剑指offer——旋转数组的最小数字

剑指offer——旋转数组的最小数字 题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。 题目分析: 从前往后找,如果在某个位置后面一个的值小于前面一个,就返回后...

2019-03-26 12:49:23 221

原创 剑指offer——二进制表示中1的个数

二进制表示中1的个数 题目描述: 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。 题目分析: 每次将n二进制表示中最后一个1变成0,其余不变,直到n为0为止。 AC代码: class Solution { public: int NumberOf1(int n) { int ans=0; while(n!=0)//只要n不为0(二进...

2019-03-24 13:37:47 203

原创 剑指offer——判断二叉搜索树后序遍历

剑指offer——判断二叉搜索树后序遍历 **题目描述: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。 class Solution { public: bool VerifySquenceOfBST(vector<int> sequence) { ...

2019-03-24 12:57:40 245

原创 剑指offer——树的子结构

剑指offer——树的子结构 题目描述: 链接:https://www.nowcoder.com/questionTerminal/6e196c44c7004d15b1610b9afca8bd88?toCommentId=2723570 来源:牛客网 输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构) /* struct TreeNode { int va...

2019-03-24 01:25:19 176

原创 牛客 编程题 —— 判断题

编程题 判断题 题目描述: 牛牛参加了一场考试,考试包括n道判断题,每做对一道题获得1分,牛牛考试前完全没有准备,所以考试只能看缘分了,牛牛在考试中一共猜测了t道题目的答案是"正确",其他的牛牛猜为"错误"。考试结束后牛牛知道实际上n道题中有a个题目的答案应该是"正确",但是牛牛不知道具体是哪些题目,牛牛希望你能帮助他计算可能获得的最高的考试分数是多少。 输入描述: 输入包括一行,一行中有三个正整...

2019-03-12 23:37:33 520

原创 编程题 DNA序列

编程题 : DNA序列 题目描述: 牛牛又从生物科研工作者那里获得一个任务,这次牛牛需要帮助科研工作者从DNA序列s中找出最短没有出现在DNA序列s中的DNA片段的长度。 例如:s = AGGTCTA 序列中包含了所有长度为1的(‘A’,‘C’,‘G’,‘T’)片段,但是长度为2的没有全部包含,例如序列中不包含"AA",所以输出2。 输入描述: 输入包括一个字符串s,字符串长度length(...

2019-03-12 23:14:40 1480

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除