- 博客(20)
- 资源 (10)
- 收藏
- 关注
原创 575. Distribute Candies
一、问题:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute t
2017-08-12 20:04:56 285
原创 500. Keyboard Row
一、题目:Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.二、解题class Solution { /* 从第一个单词开始找,先找出该单词首字母在
2017-08-12 19:03:00 249
原创 STL容器 set、 multiset、map、multimap
Set和Multiset 会根据特定的排序准则,自动将元素排序。两者不同之处是multiset允许元素重复而set不允许。set、 multiset的能力set和multiset通常以平衡二叉树完成,自动排序的优点在于令二叉树查找元素时拥有对数的性能。 另外自动排序造成set、multiset有个重要的限制:不能改变元素值。set、 multiset的操作函数c.count(val);//返回元素
2017-08-12 11:08:48 349
转载 C++ STL 之 unordered_set 介绍
简介 C++ 11中出现了两种新的关联容器:unordered_set和unordered_map,其内部实现与set和map大有不同,set和map内部实现是基于RB-Tree,而unordered_set和unordered_map内部实现是基于哈希表(hashtable),由于unordered_set和unordered_map内部实现的公共接口大致相同,所以本文以unor
2017-08-11 17:14:17 23206
原创 并发服务器的实现
一、服务器端:tcpserv01.c/************************************************************************* > File Name: tcpserv01.c > Author: zsj > Mail: 15623582731.com > Created Time: 2017年08月07日
2017-08-08 11:18:44 489
原创 并发服务器实现原理
一、监听套接字与连接套接字的区别:并发服务器中主服务器通过派生一个子进程来处理每个新的连接。如果一个子进程继续使用服务器众所周知的端口来服务一个长时间的请求。首先服务器IP地址为 12.106.32.254和192.168.42.1.服务器在它端口上执行被动打开。这是个监听套接字对,服务器在本地接口的21端口等待连接请求。、IP地址为206.168.112.219的主机启动第一个客户,它对服务器执行
2017-08-07 19:29:04 1043
原创 121. Best Time to Buy and Sell Stock
一、问题:Say you have an array for which the ith 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-08-07 15:02:06 271
原创 448、Find All Numbers Disappeared in an Array
一、问题: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your
2017-08-07 09:27:18 215
原创 561. Array Partition I
一、问题: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as
2017-08-06 19:12:13 211
原创 27. Remove Element
一、问题:Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The
2017-08-06 19:03:13 183
原创 基本套接字函数
一、socket函数为了执行网络I/O,一个进程必须做的第一件事就是调用socket函数,指定期望的通信协议类型。int socket(int family,int type,int protocol);//成功则返回正数,出错返回-1sockfd=socket(AF_INET,SOCK_STREAM,0)参数faminly :AF_INET(IPV4协议),AF_INET6(IPV6协议)typ
2017-08-06 17:11:28 415
原创 Socket套接字API简介
一、套接字地址结构:struct in_addr {in_addr_t s_addr; //32位IP地址,网络字节排序。};struct sockaddr_in{ unint8_t sin_len //结构长度 无符号的八位整数 sa_faminly_t sin_family;//协议族 AF_INET ,是一个无符号字段表示套接字结构中的地址族。 in_p
2017-08-06 15:31:54 542
原创 简单的时间服务器程序
一、客户程序:/************************************************************************* > File Name: timecli.c > Author:zsj > Mail: 15623582731@163.com > Created Time: 2017年08月06日 星期日 09时25分
2017-08-06 13:59:20 337
原创 485. Max Consecutive Ones
一、题目:Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s
2017-08-06 08:54:00 192
原创 566. Reshape the Matrix
一、题目:n MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dime
2017-08-05 19:46:16 260
原创 从0开始学习 GitHub 系列之【了解Git】
一. Git 具体命令第一步,我们先新建一个文件夹,在文件夹里新建一个文件作为git仓库mkdir test (创建文件夹test)cd test (切换到test目录)touch a.md (新建a.md文件)第二步,初始化test作为git仓库git init第三步,将a.md文件添加到仓库。git add第四步,将等待提交的文件提交。git commit -m “first commit”第五
2017-08-05 11:54:55 260
原创 从0开始学习 GitHub 系列之【初识 GitHub】
1. 写在前面我一直认为 GitHub 是程序员必备技能,程序员应该没有不知道 GitHub 的才对,没想到这两天留言里给我留言最多的就是想让我写关于 GitHub 的教程,说看了不少资料还是一头雾水,我转念一想,我当初接触 GitHub 也大概工作了一年多才开始学习使用,我读者里很多是初学者,而且还有很多是在校大学生,所以不会用 GitHub 也就不奇怪了,所以我觉得写一写关于 GitHub 的教
2017-08-04 20:37:58 283
原创 18. 4Sum
一、问题Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution se
2017-08-03 13:30:42 183
原创 17. Letter Combinations of a Phone Number
一、题目:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "
2017-08-02 20:53:41 259
原创 分治策略之最大子数组问题
问题描述:问题:一个整数数组中的元素有正有负,在该数组中找出一个连续子数组,要求该连续子数组中各元素的和最大,这个连续子数组便被称作最大连续子数组。比如数组{2,4,-7,5,2,-1,2,-4,3}的最大连续子数组为{5,2,-1,2},最大连续子数组的和为5+2-1+2=8。解问题:一、暴力解法:#include<iostream>using namespace std;class solut
2017-08-02 15:22:31 327
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人