
算法
TianXieErYang
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
求两个正整数的最大公约数和最小公倍数
输入两个正整数 m 和 n ,求其最大公约数和最小公倍数编程软件:DEV-C++ 5.11系统环境:win10代码如下:#include#include#includeusing namespace std;int main(){int a,b,min,max,s,i,m=0,n;printf("输入:\n");scanf("%d%d",原创 2017-02-19 09:11:07 · 661 阅读 · 0 评论 -
【华为笔试】数值跳跃
给出一组正整数,你从第一个数向最后一个数方向跳跃,每次至少跳跃1格,每个数的数值表示你从这个位置可以跳跃的最大长度。计算如何以最少的跳跃次数调到最后一个数。输入描述:第一行表示有多少个数n第二行开始依次是1到n个数,一个数一行输出描述:输出一行,表示最少跳跃的次数#include<iostream>using namespace std;int JMP(int a[], int...原创 2018-04-11 14:29:43 · 1912 阅读 · 0 评论 -
【leetcode】14. Longest Common Prefix
14. Longest Common PrefixProblemsolutionProblemWrite a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.Example...原创 2018-12-19 19:57:36 · 143 阅读 · 0 评论 -
【leetcode】13. Roman to Integer
13. Roman to IntegerProblemSolutionProblemRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L ...原创 2018-12-19 20:04:31 · 153 阅读 · 0 评论 -
【leetcode】88. Merge Sorted Array
88. Merge Sorted ArrayProblemSolution1、Python (36 ms)2、CProblemGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized i...原创 2019-01-15 19:59:57 · 124 阅读 · 0 评论 -
面试常用排序算法
面试常用手撸排序算法代码代码#include &amp;lt;stdio.h&amp;gt;#include &amp;lt;stdlib.h&amp;gt;#include &amp;lt;string.h&amp;gt;// Bubble sort (O(n^2))void BubbleSort(int* a, int len) { int i, j, temp;原创 2019-01-22 17:06:57 · 453 阅读 · 0 评论 -
面试常用查找算法
面试常用查找算法代码代码方面适应所有算法,都使用有序数组#include <stdio.h>#include <stdlib.h>// sequence searchint SequenceSearch(int* a, int value, int length) { int i; for (i = 0; i < length; i++)...原创 2019-01-22 20:23:32 · 1034 阅读 · 0 评论 -
【面试题】:一个栈实现另一个栈的排序
只用一个栈实现另一个栈的排序ProblemSolutionProblem要求:只用一个栈,实现另一个栈的排序,除了变量之外不可用任何类型数据结构Solution#include &lt;iostream&gt;#include &lt;stack&gt;using namespace std;void sortStack(stack&lt;int&gt; &am原创 2019-02-25 19:49:19 · 262 阅读 · 0 评论 -
【面试题】用两个栈实现一个队列
用两个栈实现一个队列ProblemSolutionProblem用两个栈实现一个队列Solution#include <stack>#include <iostream>using namespace std;void stackToQueue(stack<int> &s){ stack<int> news; ...原创 2019-02-26 10:03:49 · 190 阅读 · 0 评论 -
【leetcode】11. Container With Most Water
11. Container With Most WaterProblemSolution1、C 8 ms, faster than 65.90% 8 MB, less than 44.59%ProblemGiven n non-negative integers a1, a2, …, an , where each represents a point at coordi...原创 2019-02-26 15:08:41 · 207 阅读 · 0 评论 -
面试总结
面试总结算法算法1、动态规划背包问题(0/1背包 完全背包)2、表达式求值(中缀表达式)3、大文件中返回最高频的词语(hash)4、海量数据查找中位数(分割思想读入内存)5、给定一个整数分解成连续自然数之和,输出所有情况...原创 2019-03-26 15:22:40 · 203 阅读 · 0 评论 -
【华为笔试】字符串调整输出
给你一个原始字符串,根据该字符串内每个字符出现的次数,按照ASCII码递增顺序调整输出。举例!假设原始字符串为:eeefgghhh则每种字符出现的次数分是:(1).eee 3次(2).f 1次(3).gg 2次(4).hhh 3次重排输出后的字符串如下:efgheghen编写程序,实现上述功能。【温馨提示】(1).原始字...原创 2018-04-11 11:47:43 · 880 阅读 · 0 评论 -
【网易笔试编程题】字符串碎片
一个由小写字母组成的字符串可以看成一些同一字母的最大碎片组成的。例如,"aaabbaaac"是由下面碎片组成的:'aaa','bb','c'。牛牛现在给定一个字符串,请你帮助计算这个字符串的所有碎片的平均长度是多少。#include<iostream>#include<iomanip>#include<string.h>#include<stdlib...原创 2018-03-26 16:00:19 · 570 阅读 · 0 评论 -
水仙花数
输出所有的“水仙花数”,所谓“水仙花数”是指一个 3 位数,其各位数字立方和等于该数本身。例如,153是一水仙花数,因为153=1^3+5^3+3^3。代码如下:#include#include#includeint main(){ int i,j,k,m,n,l,s,a; printf("水仙花数:\n"); for(i=1;i<10;i++) for原创 2017-02-19 17:36:38 · 304 阅读 · 0 评论 -
判素数(质数)
写一个判素数的函数,在主函数输入一个整数,输出是否素数的信息。如果是素数,输出“是素数”;如果是不素数,输出该整数所有约数。代码如下:#includeusing namespace std;int main(){ int i,n,flag=0; printf("输入一个整数:\n"); scanf("%d",&n); int s=n/2; cout<<"是原创 2017-02-22 16:13:19 · 518 阅读 · 0 评论 -
二维数组中的查找
题目描述:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。class Solution {public: bool Find(int target, vector<vector<int> > array) { int i=0; ...原创 2018-03-16 18:49:43 · 134 阅读 · 0 评论 -
替换空格
题目描述:请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。class Solution {public: void replaceSpace(char *str,int length){ if(str==NULL && length<0) ...原创 2018-03-16 18:51:45 · 137 阅读 · 0 评论 -
从尾到头打印链表
题目描述:输入一个链表,从尾到头打印链表每个节点的值。/*** struct ListNode {* int val;* struct ListNode *next;* ListNode(int x) :* val(x), next(NULL) {* }* };*/class Solution ...原创 2018-03-16 18:53:58 · 149 阅读 · 0 评论 -
Vector容器实现未知大小的数组动态存储数据
vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个动态的数组,当程序员无法知道自己需要的数组的规模多大时,用其来解决问题可以达到最大节约空间的目的.头文件:加上 #include<vector>using namespace std;一维数组:vector<int> array;二维数组:vector<int *> array;三维...原创 2018-03-22 14:31:35 · 3021 阅读 · 0 评论 -
找出两个有序数组的公共元素
找出两个有序数组的公共元素,例:有序数组[3, 5, 7, 8, 10, 12]和有序数组[15, 10, 8, 7, 4, 3, 1]的公共元素为(8, 10)#include<iostream>#include<vector>using namespace std;int main(){ int m,n; vector<int> a; ve...原创 2018-03-22 14:53:58 · 5440 阅读 · 0 评论 -
求序列中连续子序列的最大子串
#include<iostream>#include<stdlib.h>using namespace std;int main(){ int n; int k; cin>>n>>k; int a[n]; int sum[n-1]; for(int i=0; i<n; i++) { cin>>a[i];...原创 2018-03-22 11:58:32 · 264 阅读 · 0 评论 -
【网易笔试编程题】魔法币
小易准备去魔法王国采购魔法神器,购买魔法神器需要使用魔法币,但是小易现在一枚魔法币都没有,但是小易有两台魔法机器可以通过投入x(x可以为0)个魔法币产生更多的魔法币。魔法机器1:如果投入x个魔法币,魔法机器会将其变为2x+1个魔法币魔法机器2:如果投入x个魔法币,魔法机器会将其变为2x+2个魔法币小易采购魔法神器总共需要n个魔法币,所以小易只能通过两台魔法机器产生恰好n个魔法币,小易需要你帮他设计...原创 2018-03-26 15:51:29 · 641 阅读 · 0 评论 -
【网易笔试编程题】相反数
为了得到一个数的"相反数",我们将这个数的数字顺序颠倒,然后再加上原先的数得到"相反数"。例如,为了得到1325的"相反数",首先我们将该数的数字顺序颠倒,我们得到5231,之后再加上原先的数,我们得到5231+1325=6556.如果颠倒之后的数字有前缀零,前缀零将会被忽略。例如n = 100, 颠倒之后是1. #include<iostream>#include<strin...原创 2018-03-26 15:55:54 · 321 阅读 · 0 评论 -
Bert & Transformer 笔记
Bert & Transformer 笔记论文链接链接论文链接https://arxiv.org/pdf/1810.04805.pdfgithub: https://github.com/google-research/berthttps://github.com/tianxieeryang/pytorch-pretrained-BERT链接https://www.colabu...原创 2019-06-03 10:32:52 · 342 阅读 · 0 评论