442.find all duplicates in an array

  • Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

  • Find all the elements that appear twice in this array.

  • Could you do it without extra space and in O(n) runtime?

Example:

1
2
3
4
5
Input:
[4,3,2,7,8,2,3,1]

Output:
[2,3]

解析

  • 翻译:一个整型数组,[1,n]其中n为数组大小,其中有些元素出现2次,有些出现1次,求出现2次的元素,0(n)复杂度

    Read More

412. fizz buzz

  • Write a program that outputs the string representation of numbers from 1 to n.

  • But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

n = 15,

Return:
[
"1",
"2",
"Fizz",
"4",
"Buzz",
"Fizz",
"7",
"8",
"Fizz",
"Buzz",
"11",
"Fizz",
"13",
"14",
"FizzBuzz"
]

解析

  • 翻译:写一个程序输出1到n的字符串表达,但是 如果是3的倍数,不输出对应数字的字符串,而是输出“Fizz” ,如果是5的倍数,不输出对应数字的字符串,而是输出“Buzz”, 若同时是3和5的倍数,则输出 “FizzBuzz”。

    Read More

202.happy number

  • write an algorithm to determine if a number is ‘happy’

  • A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay),or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.

Example: 19 is a happy number

1
2
3
4
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1

解析

  • 翻译: 判断一个正整数是否为一个happy-number,一个正整数各位的平方和代替次正整数,不断迭代,如果迭代出1,则为happy-number,否则不是而且会出现无限循环。

    Read More

Linux下gedit打开文件产生带波浪号(~)的备份文件

在ubuntu系统下,使用gedit编辑器打开文件(如test.md),会自动生成一个备份文件,文件名字为(原文件名+波浪号 test.md~),这种情况是为了防止系统或者编辑器突然崩溃,以恢复文件使用。但是有时候看着特别繁琐和凌乱。所以一下为解决办法,相反也可以开启自动备份功能。

如何快速删除此类备份文件

rm -rf *.*~
  • -f –force 忽略不存在文件,强制删除并不提示
  • -r –recursive 删除该目录及其子目录下所有符合条件的文件
  • .~ *代表任意,任意文件名+’.’+任意文件类型后缀+’~’,满足该条件的文件都删除

如何设置取消生成自动备份文件

  • gedit编辑器: 最大化窗口->Edit->Preferences->Editor->file saving->取消’Creat a backup copy of files before saving’选项,中文系统同理。
  • Vi/Vim编辑器:
    vi ~/.vimrc
    set nobackup
    通过以上方法可以实现删除或者取消自动备份文件功能,相反可以开启自动备份功能。

VS2010+OpenCV2.4.10的安装与配置

由于本人最近要做图像处理的一些工作,因此将相应的流程记录备份,方便自己,也为他人提供一个思路吧。

平台操作系统: Win7 32位 旗舰版

1、VS2010的安装

直接点击 AutoRun.exe或者Setup.exe按照提示一步步安装即可。需要选择安装那些模块,按自己的开发需要选择,如果实在不懂,全部安装。

2、OpenCV的安装

我用的是OpenCV2.4.10,安装非常简单。只要选择安装位置就可以自动完成,如图1。需要记住该安装地址(本文假设安装在D盘根目录下 D:\)。
图1
图2

3、OpenCV的配置

Read More

菜鸟,新的征程

我想首先我要介绍一下我的现状。我目前在北京理工读研究生,研究方向是模式识别与智能系统。

2015年07月本科毕业,那个时候自己既没有选择工作,考研也失败了。我非常焦虑和担心,幸好有父母和朋友的支持和帮助,我决定了二战。由于二战,这个网站也关闭了一年多。现在也终于重新上线了,我把他弄成了我个人的博客,分享生活,交流技术。

我个人主要会分享C|C++|Shell|Python|模式识别|ML&&DL|数据结构与算法|Markdown|Git|Linux等相关方面的内容。你对相关内容有任何看法与见解,非常欢迎一起沟通交流。

菜鸟,新的征程。New bird,New beginning。