自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Windows socket通信出现接收数据时出现recv返回大于0,但缓冲区为大小为0的问题

服务端在ubuntu服务器下,客户端在windows下,采用socket进行通信,在客户端接收数据时,出现了诡异的情况,recv返回值大于0,但缓冲区大小为0,代码如下:char buff[10];int res=recv(ClientSocket, buff, 10, 0);cout << res << endl;//返回8,表示有接收到数据cout << strlen(buff) << e

2017-11-23 20:07:58 1774 2

原创 codeblocks配置生成动态库.so的环境

1.建立工程,选择shared library2.compiler setting->Other compiler options: -shared -fPIC3.配置运行生成动态库的程序所需要的环境, 比如opencv可参考http://blog.csdn.net/llwjason5555/article/details/78276757, caffe可参考http://blog.csdn

2017-10-20 09:36:40 3912

原创 幸运的袋子

题目:链接:https://www.nowcoder.com/questionTerminal/a5190a7c3ec045ce9273beebdfe029ee 来源:牛客网一个袋子里面有n个球,每个球上面都有一个号码(拥有相同号码的球是无区别的)。如果一个袋子是幸运的当且仅当所有球的号码的和大于所有球的号码的积。 例如:如果袋子里面的球的号码是{1, 1, 2, 3},这个袋子就是幸运的,因为

2017-10-18 21:11:32 345

原创 codeblocks配置caffe环境,调用caffe模型

1.首先需要搭配好caffe的运行环境,可参考我另一篇博客:http://blog.csdn.net/llwjason5555/article/details/624240852.打开codeblocks,建立工程,右击工程,选择Build options,Linker setting左边添加opencv动态库和/caffe/build/lib/libcaffe.so,右边添加-pthread-l

2017-10-18 19:50:27 844

原创 codeblocks配置opencv环境

1.首先,先安装好opencv,可参考:http://blog.csdn.net/titer1/article/details/450700652.打开codeblocks,建立工程,右击工程,选择Build options,Linker setting左边填入usr/local/lib中的全部动态库(.so)的路径3.Search directories->Compiler: 添加usr/incl

2017-10-18 19:37:13 1131

原创 codeblocks下muduo环境的配置

1.首先,先按照教程安装编译muduo库,可参考http://blog.csdn.net/liuweihui521/article/details/525563752.打开codeblocks,建立工程,根据你前面编译的方式选择debug或者release,右键点击工程,选择Build Options,Linker setting中左边填入muduo静态库(.a)的路径以及 /usr/lib/x86

2017-10-18 10:10:38 323

原创 分饼干

题目:易老师购买了一盒饼干,盒子中一共有k块饼干,但是数字k有些数位变得模糊了,看不清楚数字具体是多少了。易老师需要你帮忙把这k块饼干平分给n个小朋友,易老师保证这盒饼干能平分给n个小朋友。现在你需要计算出k有多少种可能的数值 输入描述:输入包括两行: 第一行为盒子上的数值k,模糊的数位用X表示,长度小于18(可能有多个模糊的数位) 第二行为小朋友的人数n输出描述:输出k可能的数值种数,

2017-10-15 18:56:20 371

原创 堆砖块

题目:小易有n块砖块,每一块砖块有一个高度。小易希望利用这些砖块堆砌两座相同高度的塔。为了让问题简单,砖块堆砌就是简单的高度相加,某一块砖只能使用在一座塔中一次。小易现在让能够堆砌出来的两座塔的高度尽量高,小易能否完成呢。 输入描述: 输入包括两行: 第一行为整数n(1 ≤ n ≤ 50),即一共有n块砖块 第二行为n个整数,表示每一块砖块的高度height[i] (1 ≤ height[i]

2017-10-14 15:36:54 455

原创 回文序列

题目:如果一个数字序列逆置之后跟原序列是一样的就称这样的数字序列为回文序列。例如: {1, 2, 1}, {15, 78, 78, 15} , {112} 是回文序列, {1, 2, 2}, {15, 78, 87, 51} ,{112, 2, 11} 不是回文序列。 现在给出一个数字序列,允许使用一种转换操作: 选择任意两个相邻的数,然后从序列移除这两个数,并用这两个数字的和插入到这两个

2017-10-14 11:29:58 387

转载 一致性哈希算法

tencent2012笔试题附加题    问题描述: 例如手机朋友网有n个服务器,为了方便用户的访问会在服务器上缓存数据,因此用户每次访问的时候最好能保持同一台服务器。已有的做法是根据ServerIPIndex[QQNUM%n]得到请求的服务器,这种方法很方便将用户分到不同的服务器上去。但是如果一台服务器死掉了,那么n就变为了n-1,那么ServerIPIndex[QQNUM%n]与Server

2017-10-14 11:07:48 243

原创 双核处理

题目:链接:https://www.nowcoder.com/questionTerminal/9ba85699e2824bc29166c92561da77fa 来源:牛客网一种双核CPU的两个核能够同时的处理任务,现在有n个已知数据量的任务需要交给CPU处理,假设已知CPU的每个核1秒可以处理1kb,每个核同时只能处理一项任务。n个任务可以按照任意顺序放入CPU进行处理,现在需要设计一个方案让C

2017-10-12 10:18:07 319

原创 合唱团

题目:有 n 个学生站成一排,每个学生有一个能力值,牛牛想从这 n 个学生中按照顺序选取 k 名学生,要求相邻两个学生的位置编号的差不超过 d,使得这 k 个学生的能力值的乘积最大,你能返回最大的乘积吗? 输入描述: 每个输入包含 1 个测试用例。每个测试数据的第一行包含一个整数 n (1 <= n <= 50),表示学生的个数,接下来的一行,包含 n 个整数,按顺序表示每个学生的能力值 ai(

2017-10-10 10:01:39 267

原创 构造回文

题目:链接:https://www.nowcoder.com/questionTerminal/28c1dc06bc9b4afd957b01acdf046e69 来源:牛客网给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢? 输出需要删除的字符个数。输入描述:输入数据有多组,每组包含一个字符串s,且保证:1<=s.length<=1000.输出描述

2017-10-08 09:05:21 241

原创 single-number-ii

题目:Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without us

2017-09-29 16:54:54 150

原创 longest-consecutive-sequence

题目:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given[100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is[1, 2, 3,

2017-09-29 10:28:22 164

原创 binary-tree-maximum-path-sum

题目:Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3Return6.程序:class Solu

2017-09-29 08:59:43 255

原创 best-time-to-buy-and-sell-stock-iii

题目:Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may

2017-09-27 16:27:45 350

原创 best-time-to-buy-and-sell-stock-ii

题目:Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy o

2017-09-27 16:06:12 207

原创 best-time-to-buy-and-sell-stock

题目:Say you have an array for which the i th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock)

2017-09-27 15:56:29 207

原创 pascals-triangle-ii

题目:Given an index k, return the k th row of the Pascal’s triangle. For example, given k = 3, Return[1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space?程序:class Solution

2017-09-27 15:15:47 302

原创 pascals-triangle

题目:Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]程序:class Solution {publ

2017-09-27 14:59:53 183

原创 populating-next-right-pointers-in-each-node

题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If

2017-09-27 13:53:28 338

原创 distinct-subsequences

题目:Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be non

2017-09-27 11:04:12 167

原创 path-sum-ii

题目:Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example: Given the below binary tree andsum = 22, 5 / \

2017-09-27 10:05:42 142

原创 path-sum

题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree andsum

2017-09-27 09:54:33 134

原创 balanced-binary-tree

题目:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe

2017-09-27 09:53:12 142

原创 convert-sorted-list-to-binary-search-tree

题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.程序:class Solution {public: TreeNode *sortedListToBST(ListNode *head) { retur

2017-09-26 17:43:31 178

原创 convert-sorted-array-to-binary-search-tree

题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.程序:class Solution {public:    TreeNode *sortedArrayToBST(vector<int> &num)    {        return Arr

2017-09-26 17:05:35 224

原创 binary-tree-level-order-traversal-ii

题目:Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree{3,9,20,#,#,15,7},

2017-09-26 17:01:48 184

原创 construct-binary-tree-from-inorder-and-postorder-traversal

题目:Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.程序:class Solution {public: TreeNode *buildTree(vecto

2017-09-26 16:55:49 212

原创 construct-binary-tree-from-preorder-and-inorder-traversal

题目:Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree程序:class Solution {public:    TreeNode *buildTree(vector<

2017-09-26 16:37:08 166

原创 maximum-depth-of-binary-tree

题目: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.程序:class Solution {public: int ma

2017-09-26 16:19:14 156

原创 binary-tree-zigzag-level-order-traversal

题目:Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary

2017-09-26 11:48:57 170

原创 binary-tree-level-order-traversal

题目:Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20

2017-09-26 11:45:18 137

原创 symmetric-tree

题目: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3But the foll

2017-09-26 11:13:55 160

原创 same-tree

题目: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.程序:class Solut

2017-09-26 09:03:29 186

原创 recover-binary-search-tree

题目:Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n ) space is pretty straight forward. Could you devis

2017-09-25 21:59:39 263

原创 validate-binary-search-tree

题目:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. Th

2017-09-25 21:25:19 156

原创 interleaving-string

题目:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 =”aabcc”, s2 =”dbbca”, When s3 =”aadbbcbcac”, return true. When s3 =”aadbbbaccc”, return fa

2017-09-25 20:44:34 310

原创 unique-binary-search-trees-ii

题目:Given 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 below. 1 3

2017-09-25 19:21:01 211

空空如也

空空如也

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

TA关注的人

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