- 博客(12)
- 收藏
- 关注
原创 linux c/c++ 读取指定目录下的文件名
#include #include /*struct dirent{ long d_ino; // inode number 索引节点号 off_t d_off; // offset to this dirent 在目录文件中的偏移 unsigned short d_reclen; // length of this d_name 文件名长 unsigned char
2016-11-26 20:17:42 5984
原创 C++实现快排函数
技巧:对于每一段区间[l,r],取一个key值为a[l],接下来要将这个key值放到一个位置上使得当前它的左边的数都比它小,右边的数都比它大。存在一个交换操作;具体看代码代码:#include #include using namespace std;template void Qsort(T *a,int left,int right){ int l = left,
2016-11-23 16:15:35 4194
原创 leetcode 113. Path Sum II 二叉树求符合和值为sum的链
技巧:链表二叉树的掌握,以及链表递归深层次的了解代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(N
2016-11-22 12:05:44 302
原创 leetcode 110. Balanced Binary Tree 判断是否是一颗平衡二叉树
技巧:链表的掌握,以及auto 对于c++11的使用技巧代码:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), le
2016-11-21 21:13:15 388
原创 HashMap简单实现询问long long范围内数据出现的个数
题意:给出n个long long范围内的数,以及q个询问,每次询问x 输出数x出现的次数思路:将每个数取模%MOD,用邻接表存储数据,当前节点存储的是一个key的值v,以及v出现的次数,和与它取mod相等的上一个数代码:
2016-11-17 20:17:45 685
原创 leetcode 96. Unique Binary Search Trees 增量技巧
题意:n个节点的二叉树,输出n个节点能组成多少二叉树的形态,unique思路:n=1 ans=1n=2 ans=2n=3 ans=5n=4 ans=?假设新加入的点放在根节点的位置,那么我们可以枚举:当左边的节点个数为0,右边节点个数为2的种类:ans[0]*ans[2]=2当左边的节点个数为1,右边节点个数为1的种类:ans[1]*ans[1]=1
2016-11-13 20:54:48 287
原创 C++ 拷贝构造函数中浅拷贝与深拷贝
浅拷贝构造函数 看一段拷贝构造函数的代码#include <iostream>#include <cstring>using namespace std;class Array{public : Array(){ cout<<"Array()"<<endl; } Array(const Array &arr){ /// 拷贝构造函数
2016-11-12 13:48:02 8092 1
原创 leetcode 24. Swap Nodes in Pairs 单向链表操作
Get:当前指针a指向的地址如果是空的话,a->next无法指向任何地址将单向链表的奇偶位置互换代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(N
2016-11-11 10:08:25 302
原创 leetcode 21. Merge Two Sorted Lists 两个单向链表合并 指针与解指针
代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNod
2016-11-10 22:23:16 380
原创 leetcode 19. Remove Nth Node From End of List 单向链表删除第n个数
代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNod
2016-11-10 21:23:19 274
原创 queue 简单底层实现
代码:#include using namespace std;template struct node{ T val; node *next; node(){ next=NULL; } node(T x){ val=x; next=NULL; }};template class Que
2016-11-04 21:37:09 1060
原创 stack 底层简单实现 链表实现
代码:#includeusing namespace std;template struct node{ T val; node *next; node(){ next=NULL; } node(T x){ val=x; next=NULL; }};template class Stack{private : n
2016-11-04 21:14:14 333
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人