自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 生成N个不重复的随机数

问题描述:给定一个正整数n,需要输出一个长度为n的数组,数组元素顺序随机分布,范围为0 – n-1,且元素不能重复。 解决思路: 1)、声明一个数组N[n],并赋初值{0、1、2、3、……、n-1}; 2)、设一变量“m=n-1”; 3)、生成[0,m]间的随机数“x”,将N[x]与N[m]元素互换; 4)、对“m”做“m=m-1”,并返回到“3)”,直到“m=0”; 5)、完成上述操...

2018-10-10 23:11:49 4468

原创 linux小知识点

>:  会重写文件,如果文件里面有内容会覆盖。>>: 这个是将输出内容追加到目标文件中。如果文件不存在,就创建文件。就是如果文件里面有内容会把新内容追加到文件尾。$# 是传给脚本的参数个数$0 是脚本本身的名字$1 是传递给该shell脚本的第一个参数$2 是传递给该shell脚本的第二个参数$@ 是传给脚本的所有参数的列表$* 是以一个单字符串显示所有向脚本传...

2018-10-09 18:59:21 320

原创 快速幂

给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。将任何一个数二分直至等于1的方法:偶数时除以2,奇数时减1或者加1.  如9-8-4-2-1,以及 14-7-6-3-2-1. 快速幂就是这个思想,它把b^n拆成(b^(n/2))*(b^(n/2)).从而实现跳跃式叠次方。常规求幂:double Power(double ...

2018-10-08 08:11:03 333

原创 数组中的逆序对(分治、递归与合并)

在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数P。将P对1000000007取模的结果输出。 即输出P%1000000007输入描述:题目保证输入的数组中没有的相同的数字数据范围: 对于%50的数据,size<=10^4 对于%75的数据,size<=10^5 对于%100的数据,si...

2018-10-07 20:32:36 684

原创 滑动窗口系列题目

滑动窗口的最大值给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6,6,6,5}; 针对数组{2,3,4,2,6,2,5,1}的滑动窗口有以下6个: {[2,3,4],2,6,2,5,1}, {2,[3,4,2],6,2,5,1}, {2,3,[4...

2018-10-07 05:33:31 1550

原创 【LeetCode41】First Missing Positive

Given an unsorted integer array, find the smallest missing positive integer.Your algorithm should run in O(n) time and uses constant extra space.题意:求一个数组中最小的缺失正数。要求O(n)的时间复杂度和O(1)的空间复杂度。Example ...

2018-10-04 18:21:27 138

原创 【LeetCode 135】Candy

There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one can...

2018-10-04 17:11:59 205

原创 【LeetCode 745】Prefix and Suffix Search

Given many words, words[i] has weight i.Design a class WordFilter that supports one function, WordFilter.f(String prefix, String suffix). It will return the word with given prefix and suffix with ...

2018-10-04 10:18:43 381

原创 【LeetCode 174】Dungeon Game

The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p...

2018-10-04 08:18:43 197

原创 【LeetCode 321】Create Maximum Number

Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the digits from the same...

2018-10-04 06:46:11 438 1

原创 C++中的 引用&

引用的概念引用:就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样。引用的声明方法:类型标识符 &引用名=目标变量名;例:char ch;       char &rp=ch;1) 引用仅是变量的别名,因此引用本身并不占用内存,而是和目标变量共同指向目标变量的内存地址.2)表达式中的取地址符&不再是取变量的地址,而是用来表示该变量是引用类型的...

2018-10-04 05:30:42 310

原创 【LeetCode 002】Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers.The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return...

2018-10-02 11:18:18 144

原创 类数组的初始化

struct Point { int x, y; Point(int _x, int _y) :x(_x), y(_y) { cout<<"create new Point 2"<<endl; } Point(int _x) :x(_x) { cout << "create new Point 1" << endl; }}; 对于单...

2018-10-02 08:39:22 9740

原创 【LeetCode 001】Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam...

2018-10-02 07:31:19 132

空空如也

空空如也

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

TA关注的人

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