- 博客(67)
- 资源 (4)
- 问答 (2)
- 收藏
- 关注
原创 recv函数
函数原型:int recv(int sockfd, void *buf, int len, int flags) 函数功能:用来接收远程主机通过套接字sockfd发送来的数据,并把这些数据保存到数组buf中。 参数说明: (1) sockfd:建立连接的套接字 (2) buf:接收到的数据保存在该数组中 (3) len:数组的长度 (4) flags:一般设置为0 返回值说明:> 0
2016-01-14 22:37:04
9553
原创 Hex与Double类型之间的转换
unsigned int getbitu(const unsigned char *buff, int pos, int len) {unsigned int bits=0;int i;for (i=pos;i<pos+len;i++){ bits=(bits<<1)+((buff[i/8]>>(7-i%8))&1u);}return bits;}/将十六进制的数转换成doub
2015-12-02 16:48:01
13800
2
原创 Pascal's Triangle II
Given an index k, return the kth 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?int* getRow(int rowIndex,
2015-09-25 10:29:29
476
原创 Pascal's 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] ]int** generate(int numRows, int
2015-09-24 22:32:58
442
原创 杨辉三角序列的生成
void Pascal(int n) {if (n == 0) return;int** num = (int**)malloc(sizeof(int*)*n);for (int i = 0; i < n; i++) num[i] = (int*)malloc(sizeof(int)*n);for (int i = 0; i < n; i++){ for (int j
2015-09-21 21:28:04
501
原创 类对象的赋值和复制
对象的赋值可以采用重载运算符的方法实现: 对象名1 = 对象名2;对象的复制可以采用复制构造函数的方法实现: (1)类名 对象2(对象1) (2)类名 对象2 = 对象1 这两种方法调用的都是复制构造函数而不是构造函数,故需要提前声明复制构造函数;若没有声明复制构造函数,则这两种方法在编译时均能通过,但也没有调用构造函数,程序运行结束时却会调用析构函数。class myClass { p
2015-09-15 23:31:52
1859
原创 Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.char* multiply(char* num1, char* num2) {//获取字符
2015-09-15 16:50:54
282
原创 Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1,
2015-09-13 16:36:59
275
原创 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 using ex
2015-09-13 11:10:01
398
原创 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me
2015-09-13 11:08:48
272
原创 House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses
2015-09-07 21:25:51
96
原创 求两个字符串的最长公共子串的长度
int func(char* query, char* text) {if (query == NULL || text == NULL) return 0;int len1 = strlen(query);int len2 = strlen(text);int sum = 0;int count = 0;for (int start = 0; start < len2; start
2015-09-07 20:36:58
659
原创 Jump Game
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.Determine if you are
2015-09-05 22:21:58
338
原创 Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly
2015-09-05 18:46:26
327
原创 Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it in
2015-09-05 16:39:27
333
原创 Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).解题思路: 先求出两个数组元素个数之和numsSize,则
2015-08-27 20:22:27
344
原创 Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of the
2015-08-25 11:57:11
296
原创 Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space?解题思路: (1)用快慢指针
2015-08-25 10:41:47
305
原创 360在线笔试题:挑选镇长
题目的描述如下所示:输入输出要求如下:#include #include struct GX{int num1;//renshi ta de ren;int num2;//ta renshi de ren;};int main(void){int T;int n,m;int** guanxi;int i
2015-08-11 22:20:10
1318
原创 Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes’ values.For example, Given {1,2,3,4}, reorder it to {1,4,2,3}
2015-08-09 13:42:42
314
原创 Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.解题思路: (1)定义两个大小为2数组,一个为temp[2]存储元素,一个为times[2]存储次数 (
2015-08-05 16:58:16
355
原创 Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two
2015-07-26 22:34:54
206
原创 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You
2015-07-26 21:09:07
357
原创 Implement strStr()
即:自己实现strstr()函数 Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.解题思路: 求出两个函数的长度差值,即返回值index的取值范围int strStr(char* haystack,
2015-07-23 22:55:03
201
原创 Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.解题思路: (1)重新分配一个数组,大小为digitsS
2015-07-22 21:23:25
363
原创 Sort List
Sort a linked list in O(n log n) time using constant space complexity.解题思路: (1)将链表中的值依次取出存在一个数组中 (2)对数组进行希尔排序 (3)将排序后的元素放回链表中struct ListNode* sortList(struct ListNode* head) {struct ListNode* head1
2015-07-21 22:07:23
289
原创 Reverse Linked List
给定一个链表:1->2->3->NULL 反转后为:3->2->1->NULL;struct ListNode* reverseList(struct ListNode* head) { struct ListNode* pNode = head; struct ListNode* PreNode = NULL; struct ListNode* NewHead =
2015-07-21 21:32:00
313
原创 Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->6->NULL, m = 2 and n = 5, return 1->5->4->3->2->6->NULL. Note: Given m, n satisfy the
2015-07-21 21:28:55
273
原创 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very large,
2015-07-21 11:48:57
318
原创 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: Elements in a quad
2015-07-20 15:45:30
342
原创 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be
2015-07-20 13:40:01
432
原创 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where in
2015-07-19 23:18:11
271
原创 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly
2015-07-19 22:48:19
446
原创 求旋转数组的最小值
已知一个递增排序的旋转数组(没有重复的数),如{1,2,3,4,5}的一个旋转数组为{3,4,5,1,2},求旋转数组的最小值解题思路:(1)第一个指针总是指向前面的递增数组,最终停在最大的元素上,即元素5; (2)第二个指针总是指向后面的递增数组,最终停在最小的元素上,即元素1int findMin(int* nums, int numsSize) {int start = 0;int end
2015-07-17 23:12:20
528
原创 将一个链表后K个结点移到链表头
例如:给定链表: 1->2->3->4->5->NULL ; k = 2或k = 7 翻转后的结果为: 4->5->1->2->3->NULL.解题思路:(1)将单链表转换成循环链表 (2)根据K值确定新链表头的位置struct ListNode* rotateRight(struct ListNode* head, int k) {if (head == NULL || k == 0)
2015-07-15 21:55:44
606
原创 求一个二叉搜索树中第K个最小值
假设该颗二叉搜索树的总元素数大于等于K解题思路:用STL容器的栈来实现int kthSmallest(TreeNode* root, int k) { std::stack<TreeNode*> Stack; while (root || !Stack.empty()) { if (root) { Stack.push
2015-07-14 22:51:16
1021
原创 字符串的无重复全排列
using namespace std;void function(char* pStr, char* pBegin); bool IsSwap(char* pBegin, char* pEnd);int main(void) {char str[] = "aabc";function(str,str);return 0;}//在[pBegin,pEnd]区间中是否有字符与下标为pEnd的字符
2015-07-09 16:58:49
703
原创 arm-linux-gcc交叉编译器安装说明
Arm-linux-gcc 交叉编译器安装使用说明: 1. 解压安装包:#tar xvf arm-linux-gcc-3.4.1.tar.bz2 –C / 2. 进入解压后的文件夹,将以交叉编译器版本号命名的文件夹拷贝到/usr/local/目录下,则现在的交叉编译程序集都在/usr/local/3.4.1/bin里面 3. 修改环境变量,把交叉编译器的路径加入到PATH:修改~/.ba
2015-07-04 15:00:33
593
原创 求一个字符串中不带重复字母的最长substr的长度
问题描述:给出一个字符串,求该字符串的最长子字符串的长度,该子字符串没有重复的字符。例如:给定字符串“abcabca”,则返回的长度应该为3;再如给定字符串“aaaaaaaa”,则返回测长度应该为1.解题思路:用一个临时字符串来存储当前字符串的没有重复字符的子字符串 int lengthOfLongestSubstring(char* s) { if (s == NULL)
2015-07-02 22:29:35
579
原创 求一棵二叉树的最大深度
struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; int maxDepth(struct TreeNode* root) { if (root == NULL) return 0; else {
2015-06-29 22:12:02
407
Convert To Renex
2013-11-14
注释掉printf语句程序出现段错误
2015-12-25
攻击者能够欺骗 DNS,如何解决?
2014-12-12
TA创建的收藏夹 TA关注的收藏夹
TA关注的人