- 博客(98)
- 收藏
- 关注
转载 g++添加第三方库
root下修改/etc/profileCPLUS_INCLUDE_PATH=CPLUS_INCLUDE_PATH:路径export CPLUS_INCLUDE_PATH修改后重启一下echo | g++ -v -x c++ -E -用上面的命令可以查看当前搜索路径转载于:https://www.cnblogs.com/Zzz-y/p/9499229...
2018-08-18 23:17:00
928
转载 多个UDP监听同一个端口
测试结果:客户端的数据总是发给最后一个打开的服务器服务器代码:socket()->setsockopt()->bind()->recvfrom()/sendto() 1 #include <stdio.h> 2 #include <sys/socket.h> 3 #include <sys/types.h>...
2018-08-18 14:26:00
2212
转载 891. Super Egg Drop
You are givenKeggs, and you have access to a building withNfloors from1toN.Each egg is identical in function, and if an egg breaks, you cannot drop itagain.You know that there exists...
2018-08-13 15:21:00
146
转载 多线程聊天室服务器初步搭建
1、服务器:server.h 1 #pragma once 2 3 #include <stdio.h> 4 #include <sys/socket.h> 5 #include <sys/types.h> 6 #include <arpa/inet.h> 7 #include <netinet/in...
2018-07-31 20:56:00
139
转载 iterator_traits实现
C++中,迭代器的类型有五个,关系为:input_iterator_tag对应输入迭代器:只读。output_iterator_tag对应输出迭代器:只写。forward_iterator_tag对应向前迭代器:只能一步一步前进。bidirectional_iterator_tag对应双向迭代器: 可以前进或后退,但只能一步步来。random_...
2018-07-26 19:33:00
102
转载 227. Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty spaces. The integer division shoul...
2018-07-26 15:32:00
77
转载 210. Course Schedule II
There are a total ofncourses you have to take, labeled from0ton-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a...
2018-07-24 16:03:00
111
转载 unordered_map用法注意
C++ STL提供了 unordered_map,底层是用哈希表实现的,可以根据 key 搜索 对应的 value。资料:http://www.cplusplus.com/reference/unordered_map/unordered_map/1 template < class Key, ...
2018-07-17 09:44:00
172
转载 tcp迷你聊天室
以http://www.cnblogs.com/Zzz-y/p/9107554.html里的 server 为雏形写了一个迷你型的多人聊天室。client跟之前一样。主要对 server 做了一些改进:1、聊天室要实现收到消息后,对所有的client广播,所以这边改成建立一个线程服务一个客户,于是clientfd共享就方便的多。2、用两个数组tid和fd_array分别保存线...
2018-07-15 20:08:00
355
转载 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101]...
2018-07-14 21:04:00
54
转载 866. Smallest Subtree with all the Deepest Nodes
Given a binary tree rooted atroot, thedepthof each node is the shortest distance to the root.A node isdeepestif it has the largest depth possible amongany node in theentire tree.The su...
2018-07-10 17:04:00
86
转载 实现自己的vector
关于标准库vector的介绍:http://www.cplusplus.com/reference/vector/vector/ 1 #pragma once 2 3 #include<memory> 4 #include<cassert> 5 #include<algorithm> 6 #include<itera...
2018-07-09 20:12:00
93
转载 C++操作MySQL数据库
用C++操作MySQL数据库,linux下需要用到头文件#include <mysql/mysql.h>说明:https://blog.csdn.net/Linux_ever/article/details/50651513为了使用方便,写了一个MyDataBase类,提供一些基本的数据库操作,和一个query函数用来提供自定义查询 1 #pragma o...
2018-07-08 19:42:00
89
转载 341. Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Given the lis...
2018-07-07 17:51:00
67
转载 861. Score After Flipping Matrix
We have a two dimensional matrixAwhere each value is0or1.A move consists of choosing any row or column, and toggling each value in that row or column: changing all0s to1s, and all1s to...
2018-07-06 20:24:00
86
转载 45. Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal ...
2018-07-01 19:10:00
79
转载 856. Score of Parentheses
Given a balanced parentheses stringS, compute the score of the string based on the following rule:()has score 1ABhas scoreA + B, where A and B are balanced parentheses strings.(A)has...
2018-06-24 19:31:00
90
转载 65. Valid Number
Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>true判断字符串是否代表了有效数字。这道题有点坑,情况比较多…… 1 class Solution {...
2018-06-21 20:51:00
68
转载 844. Backspace String Compare
Given twostringsSandT,return if they are equal when both are typed into empty text editors.#means a backspace character.Can you solve it inO(N)time andO(1)space?Input: S = "a...
2018-06-09 13:42:00
111
转载 95. Unique Binary Search Trees II
Given an integern, generate all structurally uniqueBST's(binary search trees) that store values 1 ...n.Input: 3Output:[ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], [2,1...
2018-06-08 11:37:00
116
转载 重建二叉树
二叉树重建,必须要有中序遍历结果,再加上前序或后序的遍历结果。前序遍历的第一个数,就是根节点,根据这个数在中序遍历的位置,左边部分为左子树,右边部分为右子树。后序遍历的最后一个数,就是根节点,根据这个数在中序遍历的位置,左边部分为左子树,右边部分为右子树。1、前序+中序(105.Construct Binary Tree from Preorder and Inorder ...
2018-05-30 20:01:00
94
转载 linux下socket编程
综合unp前五章,写了一个服务器-客户端程序。主要功能:客户端从标准输入读入字符串发送到服务器,服务器显示。服务器接受连接后,fork()子进程实现具体操作。服务器主要过程:socket()->bind()->listen()->accept()->read(),服务器在accept一个clientfd后,fork()一个子进程服务。客户端:s...
2018-05-29 19:48:00
57
转载 C++输出保留有效数字
#include <iomanip> //保留小数点后2位cout << setiosflags(ios::fixed) << setprecision(2) << val << endl;//保留2位有效数字cout << setprecision(2) << val <&l...
2018-05-26 15:39:00
1221
转载 836. Rectangle Overlap
A rectangle isrepresented as alist[x1, y1, x2, y2], where(x1, y1)are the coordinates of its bottom-left corner, and(x2,y2)are the coordinates of its top-right corner.Two rectangles over...
2018-05-25 21:49:00
60
转载 惊群效应
惊群效应指的是在生产者和消费者模型中,生产者广播时,使得多个消费者产生响应。测试:把模拟售票系统的49行改成每次只补一张票。如果用 if , 结果当第一次补票的时候,因为是if,所有的4个线程都做出反应,但是实际的票只能满足线程1,所以导致另外3个线程提前退出。改用while, 结果cond排队的序列是1-2-3-4.第一次补票,满足了线程1,所以队列变成...
2018-05-25 20:55:00
116
转载 linux多线程实验:模拟售票系统
主要用到函数:#include <pthread.h>pthread_create(&tid[i], nullptr, Sale_ticket, static_cast<void*>(&i));//创建线程pthread_join(tid[i], nullptr);//等待线程终止pthread_mutex_t mv_num...
2018-05-23 16:11:00
2215
转载 23. Merge k Sorted Lists
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->...
2018-05-20 15:43:00
57
转载 90. Subsets II
Given a collection of integers that might contain duplicates,nums, return all possible subsets (the power set).Example:Input: [1,2,2]Output:[ [2], [1], [1,2,2], [2,2], ...
2018-05-19 21:44:00
52
转载 399. Evaluate Division
Equations are given in the formatA / B = k, whereAandBare variables represented as strings, andkis a real number (floating point number). Given some queries, return the answers. If the ans...
2018-05-11 14:12:00
79
转载 60. Permutation Sequence
The set[1,2,3,...,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence forn= 3:"123""132""213""231"...
2018-05-09 19:45:00
67
转载 stringstream用法
1、字符串分割 1 int main() { 2 string s = "asdhj,sfkkjdsi,sdni"; 3 istringstream ss(s); 4 string temp; 5 while (getline(ss, temp, ',')) 6 cout << temp <&...
2018-05-09 18:09:00
88
转载 43. Multiply Strings
Given two non-negative integersnum1andnum2represented as strings, return the product ofnum1andnum2, also represented as a string.Input: num1 = "123", num2 = "456"Output: "56088"字...
2018-05-08 18:00:00
43
转载 二叉树遍历(递归、非递归)
1、递归遍历1 void helper(TreeNode* root, vector<int>& res) {2 if (root) {3 res.push_back(root->val);4 helper(root->left, res);5 ...
2018-05-08 13:34:00
52
转载 31. Next Permutation
Implementnext permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possi...
2018-04-26 13:45:00
58
转载 34. Search for a Range
Given an array of integersnumssorted in ascending order, find the starting and ending position of a giventargetvalue.Your algorithm's runtime complexity must be in the order ofO(logn).I...
2018-04-25 12:29:00
76
转载 管道通信pipe()实验
父进程创建两个子进程,子进程通过管道向父进程传递消息。父进程先读子进程1的,再读子进程2的。 1 #include <sys/wait.h> 2 #include <sys/types.h> 3 #include <unistd.h> 4 #include <iostream> 5 #include <cstd...
2018-04-24 19:35:00
284
转载 进程通信signal()实验
调用fork()创建两个子进程,父进程接受SIGINT信号中断,之后发送16和17中断子进程。 1 #include <sys/wait.h> 2 #include <sys/types.h> 3 #include <unistd.h> 4 #include <signal.h> 5 #include <ios...
2018-04-24 12:30:00
167
转载 92. Reverse Linked List II
Reverse a linked list from positionmton. Do it in one-pass.Note:1 ≤m≤n≤ length of list.Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5->...
2018-04-23 11:38:00
51
转载 11. Container With Most Water
Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find...
2018-04-11 19:28:00
59
转载 814. Binary Tree Pruning
We are given the head noderootof a binary tree, where additionally every node's value is either a 0 or a 1.Return the same tree where every subtree (of the given tree) not containing a 1 has ...
2018-04-09 13:57:00
54
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人