KMP算法是一种改进后的字符串匹配算法,由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现,因此人们称它为克努特——莫里斯——普拉特处的下标值,不一
原创 16小时前
18阅读
KMP算法
给定一个数组和一个特定的数,使得数组中的两个数等于这个特定的数。找出这两个数的下标。
原创 16小时前
19阅读
题目描述 请编写一个方法,实现整数的乘法、减法和除法运算(这里的除指整除)。只允许使用加号。 给定两个正整数int a,int b,同时
原创 16小时前
21阅读
1.Triangle 三角形Given a triangle, find the minimum path sum from top to bottom. Each step y
原创 16小时前
20阅读
leetcode 三角形
题目描述操作给定的二叉树,将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义:/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {
原创 16小时前
24阅读
剑指offer 编程题(17):二叉树的镜像
题目描述 有一些数的素因子只有3、5、7,请设计一个算法,找出其中的第k个数。 给定一个数int k,请返回第k个数。
原创 16小时前
19阅读
题目描述从上往下打印出二叉树的每个节点,同层节点从左至右打印。class Solution { public: vector<int> PrintFromTopToBottom(TreeNode* root) { queue<TreeNode*> q; vector<int> res; if(root ==
原创 16小时前
19阅读
C++11中,针对顺序容器(如vector、deque、list),新标准引入了三个新成员:emplace_front、empla
原创 16小时前
16阅读
题目描述 有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存
原创 16小时前
14阅读
题目描述输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NU
原创 16小时前
20阅读
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link
原创 16小时前
25阅读
题目描述 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。后序序列最后一个值为root;二叉搜索树左子树值都比root小,右子树值都比root大。对于后序遍历来说,序列数组的最后一个元素一定是根节点,则根据这个元素,将前面的数组分为左、右两个部分,左侧部分都小,右侧部分都大,如果右侧部分有比该根节点小的元素
原创 16小时前
17阅读
求两个节点之间最远的距离:     (1)两个节点都是叶子结点     (2)
原创 16小时前
17阅读
题目描述输入一个链表,输出该链表中倒数第k个结点。/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindKthTo
原创 16小时前
38阅读
1.sqrt 求开方class Solution {public: int mySqrt(int x) { if (x <= 1) r
原创 16小时前
17阅读
题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { publ
原创 16小时前
36阅读
1.翻转整数Example1: x = 123, return 321Example2: x = -123, return -321class So
原创 16小时前
12阅读
1.生成矩阵class Solution {public: vector<vector<int> > creatMatrix(int n return ...
i++
原创 16小时前
14阅读
1.包围区域Given a 2D board containing 'X' and 'O', capture all regions surro
i++
原创 16小时前
17阅读
题目描述输入两{public: bool IsPopOrder(vec
原创 16小时前
23阅读
在处理 Linux 时,您需要使用一个 shell——一个可以让您访问操作系统的接口。命令需要作为输入来通知或指导计算机程序执行特定操作。虽然大多数Linux 发行版都是用户友好的,并且带有易于使用的图形界面,但了解如何使用命令行非常有用。那么让我们通过示例来学习必须知道的基本 Linux 命令。1.cdcd(Change Directory)命令是Linux中最重要、使用最广泛的命令之一。它用于
原创 16小时前
34阅读
题目描述给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
原创 16小时前
17阅读
1.Simplify Path 简化路径Given an absolute path for a file (Unix-style), simplif
原创 16小时前
17阅读
题目描述输入一个链表,反转链表后,输出链表的所有元素。三个指针 pre ,cur,next初始状态,pre是NULL,cur指向当前的头节点Hhead,next指向头节点Hhead的下一个节点B。首先从A节点开始逆序,将A节点的next指针指向prev,因为prev的当前值是NULL,所以A节点就从链表中脱离出来了,然后移动head和next指针,使它们分别指向B节点和B的下一个节点C(因为当前的
原创 16小时前
19阅读
(1) 对基类成员
1.Word Break 拆分词句 Given a non-empty string s and a dictionary wordDict contain
原创 16小时前
18阅读
题目描述一只青蛙一次可以跳上1
原创 16小时前
17阅读
一元谓词案例与二元谓词案例
原创 16小时前
27阅读
一元谓词案例与二元谓词案例
1.Compare Version Numbers 版本比较 Compare two version numbers version1 a
原创 16小时前
18阅读
原创 16小时前
16阅读