- 博客(239)
- 收藏
- 关注
原创 java 内存区域
运行时数据区(java虚拟机所管理的内存)程序计数器将要执行字节码的行号指示器;线程私有java虚拟机栈为虚拟机执行java方法服务;线程私有本地方法栈为虚拟机使用到的本地方法使用(hotspot 中合二为一)java 堆方法区类信息,常量,静态变量,即时编译后的代码缓存数据永久代(before jdk8,使用永久代实现方法区)元空间(动态改变大小,垃圾回收)运行是常量池方法区的一部分,类的版本,字段,方法,接口,等描述信息,编译产生的字面量和符号引用,运行期间的常量(Strin
2020-09-04 00:37:10 211
原创 线程安全
ReentrantLock 等待可中断ReentrantLock 可公平、非公平;synchronized 非公平ReentrantLock 可绑定多个条件(newCondition())
2020-08-25 23:42:37 239
原创 原子性,可见性,有序性
1. 原子性- read, load, assign, use, store write- 基本类型的访问,读写(long, double 非原子性协定)- monitorenter, monitorexit (jvm) ; lock, unlock, synchronized2. 可见性- volatile- synchronized (对一个变量执行unlock操作之前,必须吧此变量同步回主内存中(store, write)- final (在构造器中初始化完成后,并且...
2020-08-21 22:03:52 260
转载 Leetcode 173. Binary Search Tree Iterator
ok/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class B...
2018-10-02 21:15:48 149
转载 leetcode 166. Fraction to Recurring Decimal
okclass Solution {public: string fractionToDecimal(int numerator, int denominator) { bool pos = true; if (long(numerator) * long(denominator) < 0) pos = false; long ...
2018-10-02 17:21:15 114
转载 Leetcode 165. compare version number
class Solution {public: int compareVersion(string version1, string version2) { vector<int> a(parse_str(version1)); vector<int> b(parse_str(version2)); int len...
2018-10-01 22:07:53 113
转载 Leecode 162. Find Peak Element
可运行class Solution {public: int findPeakElement(vector<int>& nums) { return findPeakElementCore(nums, 0, nums.size() - 1); }private: int findPeakElementCore(vector&...
2018-09-27 21:56:08 178 1
转载 ycm 安装
https://www.jianshu.com/p/d908ce81017a?nomobile=yessudo apt-get install llvm-3.9 clang-3.9 libclang-3.9-dev libboost-all-dev./install.py --clang-completer --system-libclangsudo
2018-09-02 14:45:59 2244
转载 split 的实现
stackoverflow: https://stackoverflow.com/questions/236129/the-most-elegant-way-to-iterate-the-words-of-a-string/237280#237280笔试可以用,无法自定义分割#include <iostream>#include <string>#includ...
2018-08-26 15:11:04 677
转载 vimrc
https://segmentfault.com/a/1190000003962806ycm 如果编译报错在其文件夹下运行./install.py
2018-05-06 11:32:12 149
原创 带有引用计数的智能指针
来自《高质量程序设计指南 C/C++》template&lt;class T&gt;class INonintrusiveRefcountManager {public: virtual size_t addRef() = 0; virtual size_t release() = 0; virtual T* realObject() = 0; virt...
2018-04-24 11:39:24 305
转载 Semaphore
#include <mutex>#include <condition_variable>#include <thread>class Semaphore {public: Semaphore(int count_ = 0): count(count_) {} void notify() { std::unique_lock<std::mu...
2018-04-22 21:01:50 172
原创 双线程高效下载
编程之美 10 // 不确定对否class Semaphore {public: Semaphore(int count_, int max_count_) : count(count_), max_count(max_count_) {} void signal() { std::unique_lock<std::mutex> lock(m...
2018-04-22 20:42:45 245
原创 包含max 函数的栈
#include <iostream>using namespace std;const int MAXN = 100;template<typename Type>class Stack {public: Stack() { stackTop = -1; maxStackItemIndex = -1; } ...
2018-04-22 13:24:03 438
原创 BigInt
参考 http://www.cnblogs.com/studynote/p/3445398.html#include <iostream>#include <time.h>using namespace std;class BigInt {public: //BigInt(); BigInt(const char*); BigIn...
2018-04-20 17:00:10 1139
原创 类中的复制构造和赋值操作
#include <iostream>#include <algorithm>class MyStr {public: MyStr(const MyStr&); MyStr& operator = (const MyStr&);private: char *pdata;};MyStr::MyStr(const...
2018-04-12 16:57:15 249
原创 Leetcode 150. Evaluate Reverse Polish Notation
evaluate reverse polish notaion
2018-04-11 10:08:19 73
原创 Leetcode 149. Max Points on a Line
/** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Point(int a, int b) : x(a), y(b) {} * }; */class Solution {public: int maxPoi...
2018-04-06 22:33:26 86
原创 阿里编程
没跑过,记一下#include <iostream>#include <vector>#include <limits>#include <algorithm>using namespace std;/*请完成下面这个函数,实现题目要求的功能*//******************************开始写代码*****...
2018-04-03 11:04:12 134
原创 Leetcode 145. Binary Tree Postorder Traversal
递归/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cl...
2018-03-30 22:38:08 104
原创 Leetcode 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,2,3].递归/** * Definition for a binary tree nod...
2018-03-30 20:38:39 97
原创 ***Leetcode 146. LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if the ...
2018-03-30 10:56:12 144
原创 用两个栈来实现一个队列
用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。class Solution{public: void push(int node) { stack1.push(node); } int pop() { if (stack1.empty() && stack2.empty()) ret...
2018-03-29 21:57:22 153
原创 重建二叉树
输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。/** * Definition for binary tree * struct TreeNode { * int val; * TreeN
2018-03-28 20:20:25 115
转载 markdown编辑方法
# 欢迎使用Markdown编辑器写博客本Markdown编辑器使用[StackEdit][6]修改而来,用它写博客,将会带来全新的体验哦:- **Markdown和扩展Markdown简洁的语法**- **代码块高亮**- **图片链接和图片上传**- ***LaTex*数学公式**- **UML序列图和流程图**- **离线写博客**- **导入导出Markdown文件**- **
2018-03-28 20:19:08 268 1
原创 错误记录
开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。 处理: 1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并) 2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并) 3.输入的文件可能带路径,记录...
2018-03-21 15:47:27 161
原创 二维数组中的查找
class Solution {public: bool Find(int target, vector<vector<int> > array) { if (array.size() == 0) return false; if (array[0].size() == 0) return false; vecto...
2018-03-20 11:31:18 157
原创 Leetcode 138. Copy List with Random Pointer
copy list with random pointer
2018-03-18 22:52:29 103
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人