07 2020 档案

摘要:正宗归并排序算法C++版本,看图一目了然。 归并排序和快速排序都用到了分治思想。这两种排序算法适合大规模的数据排序。 归并排序的执行效率与要排序的数组的有序程度无关,所以其时间复杂度是非常稳定的,不管最好、最坏、平均时间复杂度都是O(nlogn)。 空间复杂度是O(n)。 void merge(in 阅读全文
posted @ 2020-07-31 21:48 程序员曾奈斯 阅读(112) 评论(0) 推荐(0) 编辑
摘要:正宗选择排序算法C++版本,看图一目了然。并总结三种简单排序算法时间复杂度分析 最低时间复杂度O(n2),最高时间复杂度O(n2),平均时间复杂度O(n^2) #include <iostream> #include <vector> #include <stack> #include <cstri 阅读全文
posted @ 2020-07-31 20:57 程序员曾奈斯 阅读(143) 评论(0) 推荐(0) 编辑
摘要:正宗插入排序算法C++版本,看图一目了然。 最低时间复杂度O(n),最高时间复杂度O(n2),平均时间复杂度O(n2) #include <iostream> #include <vector> #include <stack> #include <cstring> #include <string 阅读全文
posted @ 2020-07-31 20:08 程序员曾奈斯 阅读(143) 评论(0) 推荐(0) 编辑
摘要:正宗冒泡排序算法C++版本,看图一目了然。 最低时间复杂度O(n),最高时间复杂度O(n2),平均时间复杂度O(n2) #include <iostream> #include <vector> #include <stack> #include <cstring> #include <string 阅读全文
posted @ 2020-07-31 19:22 程序员曾奈斯 阅读(137) 评论(0) 推荐(0) 编辑
摘要:考察二叉树的前序遍历。 C++版本 #include <iostream> #include <vector> #include <stack> #include <cstring> #include <string> #include <queue> #include <algorithm> #i 阅读全文
posted @ 2020-07-28 21:45 程序员曾奈斯 阅读(96) 评论(0) 推荐(0) 编辑
摘要:实现对vector的截段操作。 C++版本 #include <iostream> #include <vector> int main() { vector<int> vector{1,2,3,4,5,6,7,8,9}; cout << "vectoor: "; for(auto el : vec 阅读全文
posted @ 2020-07-28 20:12 程序员曾奈斯 阅读(9867) 评论(0) 推荐(0) 编辑
摘要:二叉搜索树的后序遍历序列。这个题目应该注意二叉搜索树的后序遍历的特征:最后一个值是根节点。 C++版本 #include <iostream> #include <vector> #include <stack> #include <cstring> #include <string> #inclu 阅读全文
posted @ 2020-07-28 20:10 程序员曾奈斯 阅读(116) 评论(0) 推荐(0) 编辑
摘要:之字形打印二叉树。并非广度优先搜索,需要使用两个辅助栈。 C++版本 #include <iostream> #include <vector> #include <stack> #include <cstring> #include <queue> #include <algorithm> #in 阅读全文
posted @ 2020-07-28 18:50 程序员曾奈斯 阅读(231) 评论(0) 推荐(0) 编辑
摘要:数组问题。输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。并且保证奇数与奇数、偶数与偶数之间的相对位置不变。 C++版本 #include <iostream> #include <vector> #include <stack> 阅读全文
posted @ 2020-07-28 18:03 程序员曾奈斯 阅读(173) 评论(0) 推荐(0) 编辑
摘要:数组问题。输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。 C++版本 #include <iostream> #include <vector> #include <stack> #include <cstring> #inclu 阅读全文
posted @ 2020-07-28 16:55 程序员曾奈斯 阅读(98) 评论(0) 推荐(0) 编辑
摘要:分行从上到下打印二叉树(其实就是广度优先遍历),引用辅助队列。 不管是广度优先遍历一幅有向图还是一棵树,都要用到队列。首先把起始节点(对树而言是根节点)放入队列。接下来每次从队列的头部取出一个节点,遍历这个节点之后把它能到达的节点(对树而言是子节点)都依次放入队列。重复这个遍历过程,知道队列中的节点 阅读全文
posted @ 2020-07-28 15:17 程序员曾奈斯 阅读(122) 评论(0) 推荐(0) 编辑
摘要:从上到下打印二叉树(其实就是广度优先遍历),引用辅助队列。 不管是广度优先遍历一幅有向图还是一棵树,都要用到队列。首先把起始节点(对树而言是根节点)放入队列。接下来每次从队列的头部取出一个节点,遍历这个节点之后把它能到达的节点(对树而言是子节点)都依次放入队列。重复这个遍历过程,知道队列中的节点全部 阅读全文
posted @ 2020-07-28 09:04 程序员曾奈斯 阅读(118) 评论(0) 推荐(0) 编辑
摘要:栈的压入、弹出序列,很经典。 C++版本 #include <iostream> #include <vector> #include <stack> #include <cstring> #include <algorithm> using namespace std; // 定义辅助栈 stac 阅读全文
posted @ 2020-07-27 20:49 程序员曾奈斯 阅读(112) 评论(0) 推荐(0) 编辑
摘要:本题考查栈的使用。 C++版本 #include <iostream> #include <vector> #include <stack> #include <algorithm> using namespace std; // 定义数据栈 stack<int> stack1; // 定义辅助栈 阅读全文
posted @ 2020-07-27 15:10 程序员曾奈斯 阅读(87) 评论(0) 推荐(0) 编辑
摘要:关注了许多的技术公众号,下面做一下阅读摘要。 码农翻身、CodeSheep等公众号主要是发布一些程序相关,类似Java界的新闻,其中CodeSheep会发布一些关于Java的面试指南。 Java3y、三太子敖丙、我是帅地、cxuan等会发布一些基础学习、面试相关的硬核学习资料。 Java3y:基础为 阅读全文
posted @ 2020-07-27 14:43 程序员曾奈斯 阅读(342) 评论(0) 推荐(0) 编辑
摘要:本体考察数组的使用。注意本体使用vector的指针形式。 C++版 #include <iostream> #include <vector> #include <algorithm> using namespace std; void printMatrixInCircle(vector<vect 阅读全文
posted @ 2020-07-27 10:47 程序员曾奈斯 阅读(89) 评论(0) 推荐(0) 编辑
摘要:指针的基本知识 C++版 #include <iostream> #include <algorithm> using namespace std; int main() { char ch[6] = "hello"; char* pch = ch; // char数组可以用指针来修改 pch[0] 阅读全文
posted @ 2020-07-26 10:35 程序员曾奈斯 阅读(554) 评论(0) 推荐(0) 编辑
摘要:考察二叉树的遍历。判断前序遍历,与新增的前->右->左遍历结果是否一致。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义二叉树 struct TreeNode{ int val; struct Tree 阅读全文
posted @ 2020-07-25 21:53 程序员曾奈斯 阅读(146) 评论(0) 推荐(0) 编辑
摘要:考察二叉树的遍历。镜像对称,本解法使用的是前序遍历。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义二叉树 struct TreeNode{ int val; struct TreeNode* left 阅读全文
posted @ 2020-07-25 21:05 程序员曾奈斯 阅读(134) 评论(0) 推荐(0) 编辑
摘要:考察二叉树的遍历。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义二叉树 struct TreeNode{ int val; struct TreeNode* left; struct TreeNode 阅读全文
posted @ 2020-07-25 20:22 程序员曾奈斯 阅读(142) 评论(0) 推荐(0) 编辑
摘要:考察链表的操作,合并两个有序链表,合并后的链表仍是有序的。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* ne 阅读全文
posted @ 2020-07-25 19:37 程序员曾奈斯 阅读(101) 评论(0) 推荐(0) 编辑
摘要:考察链表的操作,将单向链表反转,返回头节点。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* next; Lis 阅读全文
posted @ 2020-07-25 19:20 程序员曾奈斯 阅读(104) 评论(0) 推荐(0) 编辑
摘要:考察链表的操作,找到单向链表中环的入口节点 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* next; List 阅读全文
posted @ 2020-07-25 18:39 程序员曾奈斯 阅读(115) 评论(0) 推荐(0) 编辑
摘要:考察链表的操作,注意使用一次遍历。相关题目:求链表的中间节点。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* 阅读全文
posted @ 2020-07-25 16:23 程序员曾奈斯 阅读(94) 评论(0) 推荐(0) 编辑
摘要:1 注册GitHub账号 到GitHub官网注册一个账号。 2 安装Git与TortoiseGit 下载并安装Git、TortoiseGit。 3 在GitHub上创建一个新的仓库 4 本地项目文件 打开本地的文件夹,除了代码等必须文件外,添加以下文件:README.md、LICENSE.txt、. 阅读全文
posted @ 2020-07-24 11:23 程序员曾奈斯 阅读(270) 评论(0) 推荐(0) 编辑
摘要:考察字符串匹配:这个题目的指针运用特别有意思。注意第30行代码,传递的是数组的地址,那么在函数中就有可能改变当前指针的地址,后面再使用*str就可能不会再指向数组首位了。 C++版 #include <iostream> #include <algorithm> using namespace st 阅读全文
posted @ 2020-07-23 10:56 程序员曾奈斯 阅读(113) 评论(0) 推荐(0) 编辑
摘要:考察字符串匹配:正则表达式。 C++版 #include <iostream> #include <algorithm> using namespace std; bool matchCore(char str[], char pattern[]){ if(*str == '\0' && *patt 阅读全文
posted @ 2020-07-23 10:15 程序员曾奈斯 阅读(203) 评论(0) 推荐(0) 编辑
摘要:算法分析神器—时间复杂度 时间复杂度是学习算法的基石,今天我们来聊聊为什么要引入时间复杂度,什么是时间复杂度以及如何去算一个算法的时间复杂度 刻画算法的运行时间 某日,克叫来了慧子打算给他补习补习一下基础知识,只见克写了一段非常简单的代码 克 你说一下这段代码会运行多长时间 这个...,得在计算机上 阅读全文
posted @ 2020-07-23 09:38 程序员曾奈斯 阅读(408) 评论(0) 推荐(0) 编辑
摘要:本题考查链表的操作。 C++版本 // 由于可能需要删除头结点,所以需要指向头结点的指针,即二级指针,有两种方式 // 方式一:参数声明为二级指针 ListNode** pHead; // 方式二:新建指向头结点的指针 ListNode* vHead = new ListNode(-1); vHea 阅读全文
posted @ 2020-07-22 21:57 程序员曾奈斯 阅读(128) 评论(0) 推荐(0) 编辑
摘要:本题考查大数问题。大数一般用字符串或者数组表示。注意,strlen()函数返回的值是数组'\0'前元素的个数,并不包括'\0'。 C++版本 #include <iostream> #include <algorithm> #include <cstring> using namespace std 阅读全文
posted @ 2020-07-22 16:54 程序员曾奈斯 阅读(385) 评论(0) 推荐(0) 编辑
摘要:本题考查大数问题。大数一般用字符串或者数组表示。注意,strlen()函数返回的值是数组'\0'前元素的个数,并不包括'\0'。 C++版本 #include <iostream> #include <algorithm> #include <cstring> using namespace std 阅读全文
posted @ 2020-07-22 16:31 程序员曾奈斯 阅读(252) 评论(0) 推荐(0) 编辑
摘要:引用字符串或者使用字符串函数 注意,在C++中,#include<string>与#include<ctring>和#include<string.h>是不一样的。 使用C中的字符串函数比如strlen(),需要引入的是#include<ctring>或者#include<string.h> 使用字 阅读全文
posted @ 2020-07-22 15:27 程序员曾奈斯 阅读(488) 评论(0) 推荐(0) 编辑
摘要:本题考查大数问题。大数一般用字符串或者数组表示。注意,strlen()函数返回的值是数组'\0'前元素的个数,并不包括'\0'。 C++版本 #include <iostream> #include <algorithm> #include <cstring> using namespace std 阅读全文
posted @ 2020-07-19 17:14 程序员曾奈斯 阅读(131) 评论(0) 推荐(0) 编辑
摘要:本题考查库函数的实现原理,特别注意用O(logn)时间求a的n次方的优化算法。 C++版 #include <iostream> #include <cmath> using namespace std; bool g_InvalidInput = false; double powerWithUn 阅读全文
posted @ 2020-07-18 20:28 程序员曾奈斯 阅读(140) 评论(0) 推荐(0) 编辑
摘要:这个题目考察的是计算机基础知识。注意int型的-1在计算机中的二进制存储为补码0xFFFF FFFF,但是计算机在展示给我们的时候,是作为原码展示。 C++版 #include <iostream> using namespace std; int NumberOf1Plus(int n){ int 阅读全文
posted @ 2020-07-18 18:48 程序员曾奈斯 阅读(130) 评论(0) 推荐(0) 编辑
摘要:一、计算机中的二进制位运算 二进制的位运算并不是很难掌握,因为位运算总共只有5种运算:与、或、异或、左移、右移。与、或和异或运算的规律我们可以用表1总结如下。 表1 与、或、异或的运算规律 与(&) 0 & 0 = 0 1 & 0 = 0 0 & 1 = 0 1 & 1 = 1 或(|) 0 | 0 阅读全文
posted @ 2020-07-18 18:31 程序员曾奈斯 阅读(1960) 评论(0) 推荐(0) 编辑
摘要:本题考察的是动态规划与贪心算法,有一个疑问,为何i<4时,products[i]=i。 C++版本 #include <iostream> #include <vector> using namespace std; // 动态规划 int maxProductAfterCutting_soluti 阅读全文
posted @ 2020-07-17 17:13 程序员曾奈斯 阅读(139) 评论(0) 推荐(0) 编辑
摘要:本题考察的是回溯算法,可以使用DFS解决问题。 C++版本 #include <iostream> #include <vector> using namespace std; int getDigitSum(int num){ int sum = 0; while(num > 0){ sum += 阅读全文
posted @ 2020-07-17 10:40 程序员曾奈斯 阅读(135) 评论(0) 推荐(0) 编辑
摘要:本题考察的是回溯算法,注意C/C++里面可以定义变量长度的数组,比如int a = 3;int b = 3;int c[a*b];。但是如果定义为bool *visited = new bool[rows*cols],就是类的类型,是不能用memset(visited, false, sizeof( 阅读全文
posted @ 2020-07-16 22:01 程序员曾奈斯 阅读(122) 评论(0) 推荐(0) 编辑
摘要:本题考察的是查找,需要注意的是数组中有相同数字的特例,如果不能很好地处理这些特例,就很难写出让人满意的完美代码。 C++版本 #include <iostream> #include <vector> using namespace std; int minInOrder(vector<int> r 阅读全文
posted @ 2020-07-16 20:28 程序员曾奈斯 阅读(118) 评论(0) 推荐(0) 编辑
摘要:这个题目需要注意,其实就是斐波那契数列。 Java版本 package zr.test; /** * @author ZR * @Classname Num_10_2 * @Description 青蛙跳台阶 * @Date 2020/7/16 17:00 */ public class Num_1 阅读全文
posted @ 2020-07-16 18:22 程序员曾奈斯 阅读(132) 评论(0) 推荐(0) 编辑
摘要:这个题目需要注意,不适用递归,使用循环写代码。Java真的比C慢太多。。。 Java版本 package zr.test; /** * @author ZR * @Classname Num_10 * @Description TODO * @Date 2020/7/15 16:42 */ publ 阅读全文
posted @ 2020-07-15 17:10 程序员曾奈斯 阅读(134) 评论(0) 推荐(0) 编辑
摘要:这个题目需要注意,使用语言自带的stack函数实现,所以栈的大小是不用我们考虑的,但可以思考一下,加入需要我们自己实现栈,那么栈的大小就会是一个问题:当往stack1插入元素至stack1栈满时,这个时候怎么操作? Java版本 package com.zr.test; import java.ut 阅读全文
posted @ 2020-07-14 15:27 程序员曾奈斯 阅读(130) 评论(0) 推荐(0) 编辑
摘要:Java版本: public class TreeNode { int val; TreeNode left; TreeNode right; public TreeNode(int val) { // TODO Auto-generated constructor stub this.val = 阅读全文
posted @ 2020-07-10 21:37 程序员曾奈斯 阅读(120) 评论(0) 推荐(0) 编辑
摘要:剑指offer版本 创建一个结点 链接两个结点(链表) 打印某个结点的值 打印pHead之后的链表 销毁pHead之后的链表 // // 《剑指Offer——名企面试官精讲典型编程题》代码 // 作者:何海涛 // // 面试题6:从尾到头打印链表 // 题目:输入一个链表的头结点,从尾到头反过来打 阅读全文
posted @ 2020-07-10 14:30 程序员曾奈斯 阅读(1563) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示