上一页 1 ··· 3 4 5 6 7 8 下一页
摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.分析:这道题很简单,循环遍历每个结点,当遇到相同的结点,则该链表结点的next就指向该链表结点next的next,否则,继续探测该节点的next结点。/** * Definition for singly-linked lis 阅读全文
posted @ 2014-03-06 20:30 Awy 阅读(147) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?confused what"{1,#,2,3}"means?> read more on how binary tree is serialized on OJ.OJ' 阅读全文
posted @ 2014-03-05 22:27 Awy 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2014-03-04 21:05 Awy 阅读(183) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文
posted @ 2014-03-03 21:25 Awy 阅读(227) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?分析:这道题限制条件是不可以用额外空间,然而我们就不能需求用栈或队列来求解了。我们换一种思路,使用两个指针,一个是走的比较快一次走两步,另一个是走的比较慢一次走一步,如果快的指针追上慢指针说明有环,否则没有。C++代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ... 阅读全文
posted @ 2014-03-02 20:44 Awy 阅读(172) 评论(0) 推荐(0) 编辑
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2014-03-01 22:09 Awy 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at 阅读全文
posted @ 2014-03-01 09:44 Awy 阅读(282) 评论(0) 推荐(0) 编辑
摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!If the integer's last digit is 0, what should the output be? ie, cas 阅读全文
posted @ 2014-02-28 21:54 Awy 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.分析:注意边界条件的判断,先判断两树是不是为空,都为空,则为true,否则递归判断存在的其他情况,判断左右子树的情况。/** * Definition for binary tree * struct TreeNode { * ... 阅读全文
posted @ 2014-02-28 00:51 Awy 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 最近再看Open vSwitch一些东西,我认为openstack官网上对这一块做了一些了解,所以就把这一块翻译出来以供参考,英语不好,翻译得很粗糙。 Open vSwitch插件是最有名的核心插件之一。Open vSwith配置由网桥和端口组成。端口呈现出连接其他一些东西,如物理接口和电缆。从在网桥上所给端口的包与其他网桥上端口是共享的。网桥可以通过Open vSwitch虚拟电缆或者通过Linux虚拟以太网电缆连接起来。此外,网桥作为网络接口到Linux出现,所以你能给他们绑上Ip地址。 在Neutron中,成为“br-int”的集成网桥直接与虚拟机和关联的服务连接。成为“br-e... 阅读全文
posted @ 2014-02-27 17:03 Awy 阅读(435) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.分析:这一题是说求出二叉树的最大深度,很显然我们会想到递归,很容易实现。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *... 阅读全文
posted @ 2014-02-26 23:42 Awy 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?分析:给出一组数组,每个元素都出现两次,只有一个元素只出现一次。要求不需要额外的存储空间,时间复杂度是O(n)。我们想到一个性质:任何一个数字与自己异或的结果都为0,故可以想到数组中一个元素出现两 阅读全文
posted @ 2014-02-26 17:31 Awy 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 题目描述:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", " 阅读全文
posted @ 2014-02-24 22:26 Awy 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 经过无数次的尝试,终于搭建好了完整的Openstack,本来VM可以获取到IP地址,但是等到我大功告成的时候,突然发现外部网络却不能ping进VM,我可是整整折腾了我几个通宵,这是哭啊。然而,皇天不负有心人,终于找到了一点头绪,我在此记下这一点,以免以后在遇到不知道怎么办。 首先我Openstack环境并没有问题,但是为什么ping不同VM呢,是因为我发现如下:在网络节点上,执行ip netns# ip netnsqdhcp-6e056e41-e48d-4119-b970-55ff7bae6f2dqrouter-5670bd67-c4ae-45d1-b77c-deb21a33500b然后我.. 阅读全文
posted @ 2014-01-11 17:20 Awy 阅读(5310) 评论(4) 推荐(1) 编辑
摘要: 自从看了Havana安装文档有关Swift的安装一节,发现H版的安装过程与以前还是有些差别的。不过大致过程还是那些。下面简单介绍下我们安装的过程吧,具体请参考官方文档http://docs.openstack.org/havana/install-guide/install/apt/content/ch_swift.html 原创博客:http://www.cnblogs.com/awy-blog/p/3507044.html一、安装前准备对于keystone的安装,请参照有关Havana的安装指南http://www.cnblogs.com/awy-blog/p/3447176.htm... 阅读全文
posted @ 2014-01-06 13:42 Awy 阅读(1106) 评论(0) 推荐(0) 编辑
摘要: 完数,顾名思义,就是一个数如果恰好等于它的因子之和。例如6=1+2+3.编写找出1000以内的所有完数#include #include int main(){ int k[100]; int i,j,ws,n; for(j=2;j<1000;j++) { ws=j; n=-1; for(i=1;i<j;i++) { if(j%i==0) { n++; ws-=i; //判断该数的因子,然后减去 ... 阅读全文
posted @ 2013-12-08 23:08 Awy 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 1.用户帐号文件/etc/passwd中存放当前系统的用户列表及用户基本的设置信息:文件中每一行对应一个用户信息,用户信息用":"来分隔,各项内容含义如下:用户名:用户密码:用户id:用户组id:备注:用户主目录:用户登录程序期中用户密码是经过加密的,如果为空表示没有密码,目前的Linux系统都采用影子密码的保护方式,真正的密码会以加密的方式保存在/etc/shadow文件中。eg: root::0:0:root:/root:/bin/bash,在创建/etc/passwd文件中,root用户名之后有两个相连的冒号,不要漏掉.2.用户口令文件/etc/shadow每行定义了 阅读全文
posted @ 2013-12-08 12:18 Awy 阅读(1301) 评论(0) 推荐(0) 编辑
摘要: 阔别已久的Java,现在捡起来偶感觉亚历山大啊,就单单一个环境的安装就搞得我焦头烂额啊。真后悔当初学习Java的时候没有记录下来这一门槛——环境的搭建,要知道学好一门语言,Develop Environment is so important.Okay,下面来描述下安装过程,就当记录下来,以防日后再用到。一、JDK的安装和配置1.进入Oracle官网下载JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html得到jdk-7u45-linux-i586.tar.gz2.解压下.. 阅读全文
posted @ 2013-12-07 23:32 Awy 阅读(320) 评论(0) 推荐(0) 编辑
摘要: 1.需求节点角色 NICs控制节点 eth0(10.10.10.51)eth1(192.168.100.51)网络节点 eth0(10.10.10.52)eth1(10.20.20.52)eth2(192.168.100.52)计算结点eth0(10.10.10.53)eth1(10.... 阅读全文
posted @ 2013-11-28 12:40 Awy 阅读(4037) 评论(2) 推荐(0) 编辑
摘要: openstack中,有时会经常出现这种错误,原因无二,一是安全组没有设置正确,二是openstack中网络配置会有些问题或者是相关的服务没有启动。 解决方法:1.安全组问题在nova.conf和neutron.conf配置中涉及到SecurityGroup,一定要设置正确,如果错误的话,不仅出现这个错误,而且还有安全组不能创建。 2.有些服务重新启动会出现Stop:Unknown instance。这个错误即使你强制启动,过一会又会自动stop。我认为还是相关的neutron服务没有配置正确。细心检查,重新启动,问题应该就不大了。 阅读全文
posted @ 2013-11-22 10:05 Awy 阅读(11891) 评论(0) 推荐(0) 编辑
摘要: 经过一天的努力,终于完成了openMPI的多节点安装,即小集群安装。本文使用的是openmpi-1.6.5,下载地址见:http://www.open-mpi.org/software/ompi/v1.6/1.安装准备1.1 首先肯定是需要安装GCC和G++编译器,这个直接apt-get就OK了;sudo apt-get g++ gfortran1.2 设置主机名先在/etc/hosts中删除原来的hostname,然后 vi /etc/hostname改成你想要的,注意必须顶行写。然后使用hostname命令来重新得到hostname, logout一下再login就会改掉。这里我用的是no 阅读全文
posted @ 2013-11-01 22:29 Awy 阅读(8203) 评论(0) 推荐(2) 编辑
摘要: 最近在写socket编程收发数据,对于如何发送和接收大量数据,一直在思考。send和recv一般缓存区大小为4K,但是如果你要传输的数据超过了这个标准该如何做呢。 我想到的就是如改写write和read函数一样,改写send和recv函数,使他们能分片传输这些大数据量的信息。int sock_send(SOCKET s,const char*buf,int len,int flags){ int n=0,ptr=0; int nLeft=len; if(buf==NULL) return 0; while(nLeft>0) { n=send(s,buf+ptr,nLeft,flags.. 阅读全文
posted @ 2013-10-30 14:46 Awy 阅读(579) 评论(0) 推荐(0) 编辑
摘要: 在Ubuntu系统中,你已经安装了mysql,即你使用sudo apt-get install mysql-server mysql-client然而使用C语言访问mysql数据库时,却发现出现了如下错误:fatal error: mysql.h: No such file or directory出现这个错误是因为系统没有安装mysql安装包 sudo apt-get install libmysql++-dev即可 编译时需要加连接-lmysqlclient.编译源程序的时候,如下命令:gcc -I/usr/include/mysql *.c -L/usr/lib/mysql -lmy.. 阅读全文
posted @ 2013-10-27 08:50 Awy 阅读(6782) 评论(0) 推荐(1) 编辑
摘要: #include #include #include using namespace std;class Employee{ string family_name; short department;public: Employee(const string& name,int dept); virtual void print() const;};Employee::Employee(const string& name,int dept):family_name(name),department(dept){}void Employee::print() const... 阅读全文
posted @ 2013-10-25 16:05 Awy 阅读(294) 评论(0) 推荐(0) 编辑
摘要: 所有版本的linux以及大多数的UNIX版本都随系统带有一个基本的、但却非常搞笑的数据存储历程集,他被称为dbm数据库。适用于存储比较静态的索引化数据库,即使用索引来存储可变长的数据结构,然后通过索引或顺序扫描数据库来检索结构,适用于处理那些被频繁访问但却很少被更新的数据,因为创建数据项时非常慢,而检索时非常快。 dbm数据库存在着各种不同的版本,他们的API接口和特性都有一些细微的差别。最初的dbm集,又有“新”的被称为ndbm的dbm集,还有GNU的dbm实现gdbm。GNU的实现版本虽然可以模拟旧版本的dbm和ndbm接口,但本身的接口和其他实现版本相比,还是有着显著的不同。大多数... 阅读全文
posted @ 2013-10-22 23:44 Awy 阅读(5542) 评论(0) 推荐(0) 编辑
摘要: 一、两个不同网段的子网相互访问或通信废话不多说了,直接上图,一目了然吧。按照如图配置,就可以实现两个不同网段的子网相互通信。二、连接上网的配置:如果想让这两个子网,不仅可以相互通信,而且还可以连接到Ineternet。那就需要三块网卡:一台机器PC1配置三块网卡eth0、eth1和eth2.eth0连接外网,eth1和eth2分别连接两个不同网段的子网。假定192.168.0.3连接外网,网关为192.168.0.1.PC2为一个网卡接入内网,IP为192.168.1.2,网关为192.168.1.1PC3为一个网卡接入另一个子网,IP:192.168.2.2,网关为192.168.2.1.现 阅读全文
posted @ 2013-10-01 22:12 Awy 阅读(3566) 评论(0) 推荐(0) 编辑
摘要: 硬盘命名: 硬盘命名基于文件,一般有如下文件方式:/dev/hda1/dev/sdb3具体含义如下:/dev:是所有设备文件存放的目录。hd和sd:他们是区别的前两个字母,代表该分区所在的设备类型,其中hd代表IDE硬盘,sd代表SCSI硬盘。a:是区别命名的第3个字母,表示分区在哪个设备上。eg./dev/hda代表第1个IDE硬盘,/dev/sdb代表第2个SCSI硬盘,/dev/sdd则代表第4快SCSI硬盘,依次类推。2:这个数字代表分区,Linux下前4个分区(主分区或者扩展分区)用数字1~4表示,逻辑分区从5开始,依次类推。eg./dev/hda2表示第1块IDE硬盘的第2个主分. 阅读全文
posted @ 2013-09-16 09:41 Awy 阅读(918) 评论(0) 推荐(0) 编辑
摘要: 本文在经过大量的实验终于不负众望成功的在两台Ubuntu 12.04上部署MPI的一个小型集群,MPICH2所用版本为mpich2-1.4.1,下载地址:http://www.mcs.anl.gov/research/projects/mpich2staging/goodell/downloads/index.php?s=downloads1.安装准备1.1 首先肯定是需要安装GCC和G++编译器,这个直接apt-get就OK了;sudo apt-get g++ gfortran1.2 设置主机名先在/etc/hosts中删除原来的hostname,然后 vi /etc/hostname改成你 阅读全文
posted @ 2013-09-09 22:25 Awy 阅读(1475) 评论(0) 推荐(0) 编辑
摘要: 每当看到这两个关键字,我都无比的头痛啊,当时看到理解了一下就明白了,但是在此遇到就忘记是怎么用的了,今天就索性写一写吧,好记性不如烂笔头呗,烂笔头不如存在网上。restrict是c99引入的,关键字restrict只用于限定指针;该关键字用于告知编译器,所有修改该指针所指向内容的操作都是基于该指针的,即不存在其他进行修改操作的途径。也就是说他只是告诉编译器,这个指针所指向的内容,只有这个指针可以修改。但事实伤也许还有其他方法可以修改这个内容。他只是给编译器提供一个保证,以保证编译器可以优化涉及指针的内容。C库中有两个函数可以从一个位置把字节复制到另一个位置。在C99标准下,它们的原型如下:vo 阅读全文
posted @ 2013-09-08 18:30 Awy 阅读(391) 评论(0) 推荐(0) 编辑
摘要: 这两个函数是最通用的I/O函数。实际上我们把所有read、readv、recv和recvfrom调用替换成recvmsg调用。类似地,各种输出函数调用也可以替换成sendmsg调用 #include ssize_t recvmsg(int sockfd,struct msghdr *msg,int flags);ssize_t sendmsg(int sockfd,stuct msghdr *msg,int flags); 这两个函数把大部分参数封装到一个msghdr结构中:struct msghdr{ void *msg_name; ... 阅读全文
posted @ 2013-09-08 13:59 Awy 阅读(2048) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 下一页