- 博客(33)
- 收藏
- 关注
原创 云服务器搭建Hbase注意事项
我的情况比较特殊,三台服务器分别来自BAT,导致在搭建过程中各种问题。1. 首先要在控制台中将对应端口的权限开放2. Hbase集群中的机器都要将/etc/hosts 添加一项 master外网IP master,否则会造成unkown hostname...
2021-05-07 20:46:22
293
原创 recv()函数中MSG_PEEK参数的解释
通常recv()函数的最后一个参数为0,代表从缓冲区取走数据,而当为MSG_PEEK时代表只是查看数据,而不取走数据。举例:例如套接字缓冲区现有序列''abc'',外部缓冲区即字符数组大小为1,每次只能从套接字中缓冲区读取一个字符。当最后一个参数为0时,调用recv(),套接字缓冲区序列变为''bc''。当最后一个参数为MSG_PEEK时,调用recv(),套接字缓冲区为''abc''。...
2019-09-01 23:36:23
4302
原创 归并排序链表实现
class Solution {public: ListNode* sortList(ListNode* head) { if(head==NULL||head->next==NULL) return head; ListNode *pre=NULL,*slow=head,*fast=head; while(f...
2019-08-26 12:51:16
204
原创 Leetcode 187. Repeated DNA Sequences
C++代码采用位运算+hashmapint hash_map[1<<20]={0};class Solution {public: vector<string> findRepeatedDnaSequences(string s) { vector<string> ret; int i,key=0,m...
2019-07-23 18:50:11
150
原创 输入一行整数,整数之间用空格隔开,读取并计算它们的和。
代码摘自刘汝佳 算法竞赛入门经典int main() { string line; while (getline(cin, line)) { int sum = 0, x; stringstream ss(line); while (ss >> x) { sum += x; }...
2019-06-19 11:34:17
11405
原创 PAT 甲级 1002 A+B for polynomials
利用hash表的思想#include<iostream>#include<vector>using namespace std;typedef struct {int exp;double coef;}node;node a[11], b[11];int main() {int ka, ...
2019-06-17 19:56:42
162
原创 PAT 甲级 1001 A+B format
这道题很简单,值得注意的只有一点,当处在字符串末尾时不要加","#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){ int a, b,count=0; cin>>a>>...
2019-06-16 20:07:06
123
原创 Leetcode 131的一点点思考
这道题是很典型的回溯算法题,卡了我两天,最后发现自己在sizeof认识上有误区,我把我的误区分享给大家。 char *s = "hello"; char s1[] = "hello"; int a, b; a = sizeof(s);//a=4 b = sizeof(s1);//b=6 char str[2][6] = { "hello","hel...
2019-05-21 08:57:32
243
原创 二维数组排序
void sort(int **arr,int row,int col){ int i,j,min; int *temp=NULL; for(i=0;i<row-1;i++){ min=i; for(j=i+1;j<row;j++){ if(arr[j][0]<arr[min][0]) ...
2019-05-14 11:50:20
140
原创 leetcode 46. Permutations
这道题有很多种思路,我这个是利用一个数组记录已经使用过的数字,持续深搜,当记录的数字等于numsSize时,保存,结束调用,回溯上一步。void swap(int *p,int *q){ int temp; temp=*p; *p=*q; *q=temp;}void dfs(int *item,int count,int *nums,int n,int *...
2019-05-01 13:32:02
247
原创 leetcode 102. Binary Tree Level Order Traversal
一道很经典的BFS题目,答题思路是在BFS中设置一个for循环,直到该层输出完毕再进入下一层。用C刷Leetcode简直了,所有的数据结构都得自己实现。。。。struct Queue{ struct TreeNode *root; int front; int rear;};void initQueue(struct Queue *Q){ Q->r...
2019-04-28 12:14:11
118
原创 Leetcode 229. Majority Element II
这是摩尔投票问题的升级版int* majorityElement(int* nums, int numsSize, int* returnSize){ int countm=0; int countn=0; int m=0; int n=0; int fre=numsSize/3; int *ret=malloc(sizeof(int)*2...
2019-04-26 12:55:49
104
原创 Leetcode 315. Count of Smaller Numbers After Self
struct BSTreeNode{ int val; struct BSTreeNode *left; struct BSTeeNode *right; int count;};void BST_insert(struct BSTreeNode *root,struct BSTreeNode *p){ if(root->val>p-&g...
2019-04-25 14:25:52
140
原创 Leetcode 449. Serialize and Deserialize BST
/*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*//** Encodes a tree to a single string. */struct s...
2019-04-24 12:50:25
127
原创 C语言实现二叉树层次遍历
struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right;};struct Queue { struct TreeNode *t; int rear; int front;};void InitQueue(struct Queue *q){...
2019-04-19 10:59:00
3705
原创 C语言实现归并排序
void merge(int *nums,int low,int mid,int high){ int i=low; int j=mid+1; int index=0; int *temp=malloc(sizeof(int)*(high-low+1)); while(i<=mid&&j<=high) { ...
2019-04-15 21:32:12
286
原创 leetcode 78. Subsets C语言
使用了位运算int** subsets(int* nums, int numsSize, int** columnSizes, int* returnSize) { int len = 1 << numsSize; int temp[100]; *returnSize = len; int **ret = malloc(sizeof(int*)*le...
2019-04-07 21:56:55
292
原创 leetcode 955. Delete Columns to Make Sorted II C语言
非常变态的一道题目,极限情况很多。。。附上代码int minDeletionSize(char **A, int ASize) { int count = 0; int flag = 1; int flag1 = 1; int i, len, j, s; int a[100], top, t; top = 0; int b[50], ...
2019-04-07 09:09:48
201
原创 codeforces 1108D - Diverse Garland C语言 贪心
题目不贴了,这个题目是我预面试时老师出的三道编程题之一。很遗憾,当时没接触过贪心算法。没有做出来。耿耿于怀啊,老师说这几道题目都很简单,现在看来确实是贪心中比较简单的了。回到题目本身,你会发现所有重复的字母,你只需考虑第一个字母,和最后一个不重复的字母,比如字符串是RRRGBRBG,重复的字母是R,与RRR挨着的是字符G,我们只需要将字符串RRR中第二个字符开始,都改成B,更复杂的也是如此。代码附...
2019-04-06 08:27:13
214
原创 946. Validate Stack Sequences C语言 fasater than 100%
bool validateStackSequences(int* pushed, int pushedSize, int* popped, int poppedSize) { int top=0; int i,j,flag=1; i=j=0; int *stack=malloc(sizeof(int)*(pushedSize+2)); stack[0]=0;...
2019-04-04 14:11:37
204
原创 leetcode 45. Jump Game II C语言
代码如下int jump(int* nums, int numsSize) { int *index=malloc(sizeof(int)*numsSize); int i,max_index1,max_index2,j,count; if(numsSize==1) return 0; count=0; for(i=0;i<nums...
2019-04-04 12:34:24
212
原创 376. Wiggle Subsequence C语言 自动状态转换机
int wiggleMaxLength(int* nums, int numsSize) { int i, length, STATE; length = 1; STATE = 0; const int BEGIN = 0; const int UP = 1; const int DOWN = 2; if (numsSize == 0)...
2019-04-03 09:46:01
128
原创 leetcode 92 C语言 代码写的很混乱
写的很混乱,见笑了,要考虑M=1的特殊情况struct ListNode* reverseBetween(struct ListNode* head, int m, int n) { struct ListNode *p,*q,*r,*pre,*s; int i=1; p=head; if (m == 1) { q = NULL; ...
2019-03-30 14:34:20
270
原创 leetcode 295 利用一个大顶堆和一个小顶堆实现
typedef struct { int *data1; int index1; int *data2; int index2;} MedianFinder;/** initialize your data structure here. */MedianFinder* medianFinderCreate() { MedianFinder *h;...
2019-03-29 17:45:21
349
原创 leetcode 215 C语言 利用维护一个拥有K个元素的小根堆实现
时间复杂度为logk*nstruct LittleHeap { int *data; int index; int Maxsie;};void InitHeap(struct LittleHeap *h, int len){ h->data = malloc(sizeof(int)*len); h->index = 0; h-...
2019-03-28 15:54:04
241
原创 leetcode 224 实现简单计算器
编译器:VS2017语言:C基本算法网上有很多,就是用两个栈来实现。我这个算法不太好,将‘(’也入栈了,复杂了许多。我贴下源代码,供大家参考。long char2int(char *p,char *q){ long result=0; while(p!=q) { result=result*10+*p-48; p=p+1; ...
2019-03-27 11:49:27
487
3
原创 C语言单链表实现选择排序
链表实现选择排序有两种方法,一种是交换节点内的数据,比较简单。我这里使用的是第二种方法,交换节点。#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#pragma warning(disable:4996)typedef struct Node {...
2019-03-12 12:00:27
5374
原创 求30000以内的互满数
编译器:VS2017语言:C#include<stdio.h>#include<stdlib.h>#include<string.h>#pragma warning(disable:4996)int factor(int i){ int s = 0; for (int j = 1; j <i; j ++) {...
2019-03-09 11:52:06
1573
2
原创 输入若干个整数(以0结束)逆序构建双向链表
编译:VS2017语言:C#include<stdio.h>#include<stdlib.h>#include<string.h>#pragma warning(disable:4996)typedef struct Node { int data; struct Node *pre; struct Node *nex...
2019-03-08 21:58:16
1378
原创 用Eratoshenes筛选法求素数
编译器:VS2017语言:C代码实现的是1-200之间的素数#include<stdio.h>int main(){ int prime[201]; int i, d; for (i = 2; i < 201; i++) prime[i] = i ; for (d = 2; d*d <= 200; d++)...
2019-03-08 21:46:51
584
原创 codeforces 1065B Vasya and Isolated Vertices C语言答案
Vasya has got an undirected graph consisting ofnnvertices andmmedges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edge...
2019-02-28 09:22:15
318
原创 Leetcode 561 . Array Partition I 关于插入排序的疑问
这道题目很简单,排序后将偶数位相加就可以了。但要求排序时间复杂度不能为O(n^2),所以可以选择快速排序。我一开始没想到用快速排序,使用的插入排序。runcode时提示runtime error。输入为[7,3,1,0,0,6]。我在本地使用vs2017测试正常,我手写验证也没有出界,很郁闷,盼望大神指导。疑问已经解决,j值不可以为-1,也是醉了。。。。以下为代码:int arrayP...
2019-02-28 08:47:55
155
原创 windows下C语言实现TCP通信
编译器:vs2017语言:c语言具体的原理可以在其他博客看到。在我学习winsock编程时,发现那些博客代码居然在我机器上没一个能运行,可能是我水平有限。于是我根据winsock相关知识,自己动手实现了一个,亲测能用,以下是代码。服务器端#include<stdio.h>#include<Winsock2.h>#include<time.h>...
2019-02-27 20:47:15
8274
14
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人