- 博客(37)
- 收藏
- 关注
原创 Sum of Square Numbers
题目描述:Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.Example 1:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5
2017-07-21 10:24:44 381
转载 Repeated DNA Sequences
注:这种方法是在leetcode的讨论区看到的,所以说是转载,如有不妥,私信删除。题目描述:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful t
2017-05-17 21:06:21 323
原创 Delete Operation for Two Strings
题目描述:Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.Example 1:
2017-05-16 21:25:51 944
原创 Kill Process
题目描述:Given n processes, each process has a unique PID (process id) and its PPID (parent process id).Each process only has one parent process, but may have one or more children processes. Thi
2017-05-16 21:08:12 720
原创 Subarray Sum Equals K
问题描述:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output: 2思路:记录
2017-05-02 19:52:05 838
原创 Game of Life
题目描述:According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board
2017-05-01 11:24:38 364
原创 Permutation in String
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.Ex
2017-05-01 10:31:32 611
原创 Brick Wall
题目描述:There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the
2017-04-29 14:33:51 322
原创 Minesweeper
Let's play the minesweeper game (Wikipedia, online game)!You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' represents an unrevealed empty squar
2017-04-28 17:06:02 241
原创 Convert BST to Greater Tree
题目描述:Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in B
2017-04-27 19:50:13 312
原创 Diameter of Binary Tree
题目描述:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path m
2017-04-26 11:17:03 248
原创 Binary Tree Tilt
题目描述:Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all r
2017-04-26 09:34:21 257
原创 Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1
2017-03-02 00:02:01 469
转载 Number of Digit One
题目:给定一个十进制正整数N,写下从1开始到N所有整数,然后数一下其中出现的所有1的个数思路:这道题在编程之美里有详细的解题过程,我这里复制一下,供大家参考假设N=abcde,如果要计算百位上出现1的次数,它将受到三个因素影响:百位上的数字,百位以下的数,和百位以上的数。(1)如果百位上的数字为0,百位上出现1的次数由更高位决定,比如12013,百位出现1的情况是:100-19
2017-03-01 19:11:32 432
转载 Unique Binary Search Trees II
题目描述:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown b
2017-02-27 13:03:45 247
原创 Find Largest Value in Each Tree Row
思路:变量level标识节点的深度(假设从0开始),vector res存放结果,Fun函数遍历整个树,当遍历到第i层时,如果res的长度小于i+1,则将该节点的数据加入res中,如果res长度大于等于i+1,则将该节点的数据与res[i]进行比较,如果大于res[i],则替换,这样保证res[i]最终存放的是i层最大的数void Fun(int level, vector& re
2017-02-26 19:46:33 380
原创 Find Bottom Left Tree Value
思路:建立一个有2个元素的vector,第一个元素存放叶子的深度,第二个叶子存放元素值 vector Fun(int level,TreeNode* node) { vector res(2,0); if (node==NULL) return res; if (node->left==NULL&&node->r
2017-02-26 18:20:49 305
原创 Base 7
题目要求:输入一个整数,将其7进制以字符串格式输出思路:比较简单,除k取余法 string convertToBase7(int num) { int tmp=abs(num); string ans=""; if (tmp==0) ans="0"; while(tmp) {
2017-02-24 23:28:28 350
转载 Ubuntu终端常用的快捷键
Ubuntu中的许多操作在终端(Terminal)中十分的快捷,记住一些快捷键的操作更得心应手。在Ubuntu中打开终端的快捷键是Ctrl+Alt+T。其他的一些常用的快捷键如下:快捷键功能Tab自动补全Ctrl+a光标移动到开始位置Ctrl+e光标移动到最末尾Ctrl+k删除此处至末尾的所有内容
2016-06-28 16:58:12 368
转载 Linux GCC常用命令
1简介2简单编译2.1预处理2.2编译为汇编代码(Compilation)2.3汇编(Assembly)2.4连接(Linking)3多个程序文件的编译4检错5库文件连接5.1编译成可执行文件5.2链接5.3强制链接时使用静态链接库1简介GCC 的意思也只是 GNU C Compiler 而已。经过了这么多年的发展,GCC 已经不仅仅能支持 C
2016-06-27 21:49:38 229
转载 pthread_join函数
pthread_join函数pthread_join使一个线程等待另一个线程结束。 代码中如果没有pthread_join主线程会很快结束从而使整个进程结束,从而使创建的线程没有机会开始执行就结束了。加入pthread_join后,主线程会一直等待直到等待的线程结束自己才结束,使创建的线程有机会执行。 所有线程都有一个线程号,也就是Thread ID。其类型为pthread_t
2016-06-20 21:27:03 1285
转载 Python中super
在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1:代码段1:class A:def __init__(self): print "enter A" print "leave A"class B(A):def __init__(self): print "enter B" A.
2016-05-24 09:25:32 420
转载 Python中的引用和拷贝浅析
一、引用和拷贝(references and copies)当程序中使用=赋值操作符时,例如a=b,对于不可变的对象,a作为b的一个拷贝被创建,a和b将指向不同的内存地址,a和b相互独立。复制代码代码如下:def TestCopy(): a = 10 b = a a =20 print (b) #b still is
2016-04-25 11:44:36 313
原创 linux eclipse 下 Symbol 'std’could not be resolved 问题的解决
1 右击你的project2 选择properties3 c/c++ general4 paths and symbols5 includes——language;选择GNU c/c++6 重新保存project
2016-04-20 09:18:31 5003
原创 UNIX环境高级编程一书中见到的命令
1 od 格式化输出文件中的数据例如:od -c file 选择ASCII码字符或者是转义字符输出2 du 显示文件中块的数量例如:du -s file 返回制定文件和目录中的所有块3 wc 统计指定文件中的字节数、字数、行数,并将统计结果显示输出。如果没有给出文件名,则从标准输入读取。wc同时也给出所指定文件的总统计数。例如: wc -c file 统计字节数
2016-04-12 09:13:08 323
转载 Ubuntu下提示/boot空间不足解决办法
在安装 Ubuntu的时候 , 给/boot文件目录分配空间的时候,是100M,/boot可以单独分成一个区,也可以不单独分,在/(根目录)下也会自动为其创建一个boot目录。顺便提一下,Linux分区是树结构的,/为根目录,在其目录下会分各个执行不同工作的目录,所以在分区的时候完全可以只分一个根分区和一个swap(虚拟内存)分区。如果分的细微一点,为/boot单独分区的话,100M足够,bo
2016-04-12 09:08:08 513
转载 Linux中的文件i节点
linux文件系统是Linux系统的心脏部分,提供了层次结构的目录和文件。文件系统将磁盘空间划分为每1024个字节一组,称为块(也有用512字节为一块的,如:SCOXENIX)。编号从0到整个磁盘的最大块数。 全部块可划分为四个部分,块0称为引导块,文件系统不用该块;块1称为专用块,专用块含有许多信息,其中有磁盘大小和全部块的其他两部分的大小。从块2开始是i节点表,i节点表中含有i
2016-04-09 11:27:03 910
原创 linux下文件的一些特性的判断方法
1、是否可以设置偏移量或确定打开文件的当前偏移量off_t currpos;currpos=lseek(fd, 0, SEEK_CUR);注:fd是文件描述符,0是要增加的偏移量, SEEK_CUR表示从当前偏移量位置增加偏移量
2016-03-30 15:58:22 420
转载 常用vi编辑器命令行
游标控制h游标向左移j游标向下移k游标向上移l (or spacebar)游标向右移w向前移动一个单词b向后移动一个单词e向前移动一个单词,且游标指向单词的末尾(移到当前句子的首部)移到下一个句子的首部{移到当前段的首部
2016-03-30 11:16:00 2958
原创 apue.h
我看的是unix环境高级编程的第三版里面很多例子都用到了apue .h的头文件,我在这里讲述一下如何配置书中的例子代码在http://www.apuebook.com/可以下载apue.h在所下载代码文件夹里include下,error.c 在lib下1将apue.h和error.c复制到linux下/usr/iuclude目录下,用到指令cp2编辑apue.h# cd /
2016-03-30 11:05:16 522
转载 时间计算
1、 gettimeofday 函数计时 gettimeofday 是一个库函数,包含在 time.h 中。它的功能是查询系统时钟,以确定当前的日期和时间。相对于间隔计数的小适用范围和周期计数的麻烦性, gettimeofday 是一个可移植性更好相对较准确的方法。它的原型如下: struct timeval { lo
2016-03-29 09:57:03 560
转载 学习linux步骤
我想大概可以分为4个阶段,水平从低到高 从安装使用=>linux常用命令=>linux系统编程=>内核开发阅读内核源码 其中学习linux常用命令时就要学会自己编译内核,优化系统,调整参数 安装和常用命令书太多了,找本稍微详细点的就ok,其间需要学会正则表达式 系统编程推荐《高级unix环境编程》,黑话叫APUE 还有《unix网络编程》 这时候大概还需要看资料理解elf文
2016-03-23 15:59:08 515
翻译 KCU105自测
KCU105自测一、KCU105组成元件KCU105组成元件如图1所示。图1 KCU105组成元件 二、KCU105自测 Step1:设置配置开关 将开关SW15-6打在关闭状态(如图1中28区域所示)。备注:SW15-6(FPGA_M2)用于选择配置模式,其中0代表masterSPI 配置模式;1代表JTAG配置模式。 Step2
2016-03-22 15:29:56 3946
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人