自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(100)
  • 收藏
  • 关注

原创 leetcode 502. IPO

multiset 与 priority_queue 联系: 可以实现 大小顶堆;区别: 删除元素时,multiset 会把相同元素值都删除!!代码 1 :(Accept) class Solution {public: int findMaximizedCapital(int k, int W, vector& Profits, vector& Capitals) {

2017-02-09 19:08:25 637

原创 leetcode 503. Next Greater Element II

题意:给定一个环形数组 nums, 对于每个元素e,找出e右边出现的第一个e',满足e‘ > e,若不存在e‘,令e’ 等于 1;Example:给定 nums = {1, 2, 1},返回 {2,-1, 2} 思路:1.  从右向左利用栈保持一个升序数组 sta,若第 i 个元素与 sta 的头元素相比:a. nums[i] >= sta.top(), sta循环弹出头元

2017-02-09 16:25:10 1163

转载 C++中Reference与指针(Pointer)的使用对比

reference VS pointer定义:                                               与pointer 类似,一个reference是一个对象(object),可以用来间接指向另一个对象。一个reference的声明与pointer的声明的实质语法结构是相同的。 例如:int i = 3;int *pi = &i; // po

2016-11-19 15:08:20 810

转载 Linux 基础命令 文件查找

查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 find .|xargs grep -ri "IBM" -l 1.正则表达式    (1)正则表达式一般用来描述文本模式的特殊用法,由普通字符(例如字符a-z)以及特殊字符(称为元字符,如/、*、?等)组成。   (

2016-11-03 16:43:53 274

转载 Linu 添加自己的库文件路径

库文件在连接(静态库和共享库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的。一般 Linux 系统把 /lib 和 /usr/lib 两个目录作为默认的库搜索路径,所以使用这两个目录中的库时不需要进行设置搜索路径即可直接使用。对于处于默认库搜索路径之外的库,需要将库的位置添加到库的搜索路径之中。设置库文件的搜索路径有下列两种方式,可任选其一使用:

2016-11-02 21:10:08 230

原创 linux 添加环境变量

有些命令的路径没有在PATH环境变量中,可以用echo $PATH命令查询得知,添加路径到PATH环境变量的方法如下:(如添加/sbin到PATH环境变量中)(1)如果只想在本次开机过程中临时性的添加修改,下次开机就无效的话,可以输入 export PATH=$PATH:/sbin(2)如果只给当前用户永久添加,则在~/.bash_profile中的靠近末尾有类似这样的一行PA

2016-11-02 20:37:15 408

原创 leetcode 435. Non-overlapping Intervals

/** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int e) : start(s), end(e) {} * }; */static b

2016-10-30 22:43:23 399

原创 leetcode 439. Ternary Expression Parser

题意:Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of digits

2016-10-23 13:53:07 476

原创 leetcode 438. Find All Anagrams in a String

题意:Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will n

2016-10-23 13:43:38 1045

原创 C++ inline 与#define 区别联系

1、inline与#define内联函数是代码被插入到调用者代码处的函数。如同 #define 宏,内联函数通过避免被调用的开销来提高执行效率,尤其是它能够通过调用(“过程化集成”)被编译器优化。 2、区别内联函数在编译时展开,而宏是由预处理器对宏进行展开内联函数会检查参数类型,宏定义不检查函数参数 ,所以内联函数更安全。宏不是函数,而inline函数是函数

2016-10-22 18:49:09 4834

原创 leetcode facebook面试 convert bst to double-linked list

题意:convert  bst to double-linked list代码:struct BSTree { BSTree(int v) :val(v), left(NULL), right(NULL) {} ~BSTree() { if (left) delete left; if (right) delete right; } int val; BSTree*

2016-10-19 22:15:54 673

转载 C++ 内存泄露检测方法

在debug模式下以F5运行:#define CRTDBG_MAP_ALLOC #include #include //在入口函数中包含 _CrtDumpMemoryLeaks(); //即可检测到内存泄露 //以如下测试函数为例: int main() { char* pChars = new char[10];

2016-10-19 21:14:22 274

原创 leetcode face面试题 Minimal run time scheduler

题意:Given a task sequence tasks such as ABBABBC, and an integer k, which is the cool down time between two same tasks. Assume the execution for each individual task is 1 unit.For example, i

2016-10-19 20:11:48 1643

原创 leetcode facebook 面试题 Merge two interval lists

题意:Given A and B two ascending sorted interval lists, A has no overlap inside A and B has no overlap inside B. Write the function to merge two interval lists, output the result with no overlap. As

2016-10-19 18:34:14 1457

原创 leetcode 432. All O`one Data Structure

class AllOne {private: /* * 1、将Value相同的string放置到链表:strings * 2、记录该value的值:val */ struct ListOfString{ ListOfString(int v, string str):val(v){ strings.push_fro

2016-10-19 12:20:55 718

原创 418 Sentence Screen Fitting

class Solution { // 利用一个数组记录从0。。。col - 1位置开始排列setences时,最后一个string的位置public: int getNumber(vector setences, int row, int col) { vector> record(col); int whichRow, whichCol; for (int star

2016-10-10 22:23:11 654

原创 编译问题_part1

添加头文件 -I例如在/home/work/include/目录下有编译foo.c所需头文件def.h,为了让GCC能找到它们,就需要使用-I选项:$ gcc foo.c def.h -I/home/work/include -o foo

2016-10-08 22:37:53 207

原创 leetcode 410 Split Array Largest Sum

二分查找:个人总结的二分查找有两种: 1、二分对象为索引。例如,有序表查找某个元素的存在性2、二分对象为值(所求值)。例如,本题。先确定ret的范围[low,high],然后,不断验证ret,从而缩小范围class Solution {public: int splitArray(vector& nums, int m) { long high = 0, lo

2016-10-06 22:47:10 1024

转载 struct结构体

1. C语言结构体(struct)常见使用方法: 点击打开链接纠错: X86_64体系中,struct 结构体默认还是4字节 2.  C/C++:结构体常见错误: 点击打开链接

2016-10-01 16:44:15 237

原创 leetcode 227. Basic Calculator II

class Solution {public: int calculate(string s) { istringstream in('+' + s + '+'); // 这一步很好,简化了问题 int ret = 0; int num; int partial = 0; char op; w

2016-09-29 22:35:43 221

原创 树状数组求区间最值

#define lowbit(i) (-i & i) // 二进制数字最低位'1'和其后'0'组成的数字templateclass BinaryIndexedTree {public: BinaryIndexedTree(const vector& arr) :LEN(arr.size()) { ori = arr; ori.insert(ori.begin(), INT_MA

2016-09-29 16:33:57 971

原创 最长不重复子串

int theLongestSubstring(const string& str) { vector visited(128, false); // 英文字符, hashTable int ret = 0, head = 0, tail = 0; for (; head < str.size();) { if (visited[str[head]]) { re

2016-09-28 14:26:00 151

原创 最长重复子串(可重叠)

void getNext(vector& next, const string& s) { // 利用KMP算法求解,时间复杂度O(n*n) next.resize(s.size() + 1); // 多加一位 next[0] = -1; int k = -1, i = 0; while ( i < s.size()) { if (k == -1 || s[i] == s[k] )

2016-09-28 09:47:16 413

原创 leetcode 221. Maximal Square

class Solution {// 最大正方形面积 public: int maximalSquare(vector>& matrix) { if (matrix.empty()) { return 0; } long len = 0; vector> dp(matrix.size(), vector(matrix[0].size(),

2016-09-27 19:59:55 190

原创 leetcode 67.Minimum Window Substring

/ 双指针, 哈希表class Solution {public: string minWindow(string s, string t) { vector cnt(128, 0); for (int e : t) { cnt[e]++; } int begin, minWindowLen = INT_MAX; int tLen = t.size(); for (in

2016-09-27 15:06:36 151

原创 trie

struct TrieNode { const static unsigned LETTERS_NUM = 26; bool hasString; struct TrieNode* next[LETTERS_NUM]; TrieNode() : hasString(false) { for (int i = 0; i < LETTERS_NUM; ++i) next[i] =

2016-09-26 21:36:32 192

原创 leetcode 212. Word Search II

trie + backtrackingclass Solution {public: vector findWords(vector>& board, vector& words) { TrieNode* root = new TrieNode(); for (auto str : words) insert(root, str); visited.resize(board

2016-09-26 21:06:39 323

原创 APUE_chapter4 文件和目录 part2

4.6 新文件和目录的所有权1、新文件的用户ID设置为进程的有效用户ID。2、新文件的组ID可以是进程的有效组ID。3、新文件的组ID也可以是它所在目录的组ID。4.7 函数access和 faccessat #include #include #include #include int main(int argc, char* argv[]){ if (arg

2016-09-22 14:48:00 263

转载 C++_Primer_chapter18 4.嵌套类

定义:在一个类的内部定义另一个类,我们称之为嵌套类(nested class),或者嵌套类型。之所以引入这样一个嵌套类,往往是因为外围类需要使用嵌套类对象作为底层实现,并且该嵌套类只用于外围类的实现,且同时可以对用户隐藏该底层实现。 虽然嵌套类在外围类内部定义,但它是一个独立的类,基本上与外围类不相关。它的成员不属于外围类,同样,外围类的成员也不属于该嵌套类。嵌套类的出现只是告诉外围类

2016-09-21 19:46:10 250

原创 C++_Primer_chapter18 3.类成员的指针

#include class Example{public: int elem; Example(int e) : elem(e) {} int getElem() const{ return elem; } void setElem(int e) { elem = e; }};void fun() { }int main() { Example example

2016-09-21 16:02:16 224

原创 C++_Primer_chapter18 2. 运行时类型识别

一、dynamic_cast#include class base {public: virtual ~base() { } virtual void isWhat() { std::cout << "base" << std::endl; }};class derived: public base {public: void isWhat() { std::cou

2016-09-21 10:38:43 238

转载 extern, static, const 联系区别

extern:一、基本解释:extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义。此外extern也可用来进行链接指定。    第一,当它与"C"一起连用时,如: extern "C" void fun(int a, int b);则告诉编译器在编译fun这个函数名时按着C的规则去翻译相应的函数名而不是C++的

2016-09-20 22:32:24 298

原创 C++_Primer_chapter18 7.3 链接指示:extern “C”

// c.h头文件#ifndef C_H#define C_H#ifdef __cplusplusextern "C" {#endif void print(int i);#ifdef __cplusplus}#endif#endif// c.cpp 源文件#include "c.h"#includevoid print(int i) { std::co

2016-09-20 22:03:45 257

转载 C++_Primer_chapter18 7.2 volatile

1. volatile 关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。声明时语法:volatile int  vInt; 当要求使用 volatile 声明的变量的值的时候,系统总是重新从它所在的内存读取数据,即使它前面

2016-09-20 15:54:08 270

原创 C++_Primer_chapter18 5.联合(union)

class Token {public: enum TokenType {CHAR, INT, DOUBLE}; TokenType tok; union { // 匿名联合 char _char; int _int; double _double; };};void print(Token token);int main() { Token token; toke

2016-09-20 10:47:59 304

原创 leetcode 373. Find K Pairs with Smallest Sums

思路: 1. 利用数组mark记录nums1中每个元素[i]当前与nums2中关联的位置[ji],初始关联状态为[0, 0], [1, 0], … , [i, 0], …, [nums1.size()-1,0]; 2. 利用小顶堆比较这nums1.size()个状态对应的值( nums1[i]+nums2[ji] ),找出当前的最小值。更新mark[min]的值,并将(nums1[min]

2016-09-19 21:29:10 207

原创 leetcode 402. Remove K Digits

class Solution {// 考察队数据结构stack 的使用public: string removeKdigits(string num, int k) { deque _deque; int cnt = 0; for (int i = 0; i < num.size(); ++i){ while (!

2016-09-19 20:16:06 253

原创 leetcode 400. Nth Digit

题目不难,但是debug了半天。 1. 时刻注意溢出问题2. 当sequence从1开始,还是从0开始,这是个问题。。。class Solution {public: int findNthDigit(int n) { long cnt = 9, // 时刻注意溢出问题 num = 1; while (n > cnt *

2016-09-19 19:18:50 175

原创 APUE_chapter4 文件和目录 part1

4.4 设置用户ID和设置组ID1. SUID、SGID、SBIT:点击打开链接

2016-09-16 22:32:57 292

原创 C++_Primer chapter9 3.顺序容器的操作

#include #include using namespace std;int main() { vector vec(20, 1); cout << vec.capacity() << endl; // print 20 cout << vec.size() << endl; // print 20 vec.reserve(100); // 预留空间 cout << v

2016-09-16 22:32:27 192

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除