自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(59)
  • 收藏
  • 关注

转载 Vim 使用

原先写了一段时间的vim,还是很多功能不会用。下面记一下,以下内容转自鸟哥Linux (http://vbird.dic.ksu.edu.tw/linux_basic/0310vi_2.php)(http://vbird.dic.ksu.edu.tw/linux_basic/0310vi_3.php)   第十章、vim 程序编辑器

2016-03-22 06:19:52 257

转载 C | varied number of arguments funciton

原文地址:http://www.geeksforgeeks.org/how-to-count-variable-numbers-of-arguments-in-c/How to Count Variable Numbers of Arguments in C?C supports variable numbers of arguments. But there is no la

2016-03-20 04:28:15 199

原创 C | 为什么不能在函数里用sizeof(arr)/sizeof(*arr)来求数组大小

原先就碰到过这个问题,一直不知道为什么。考虑下面代码:#includevoid fun(int arr[]) { int i; /* sizeof should not be used here to get number of elements in array*/ int arr_size = sizeof(arr)/sizeof(arr[0]);

2016-03-19 02:50:35 6155 1

原创 C | Macro

转自:http://www.geeksforgeeks.org/write-a-c-macro-printx-which-prints-x/http://www.geeksforgeeks.org/interesting-facts-preprocessors-c/Macro是在preprocessor时的字符串替换,一切与compiler无关,缺点是当你debug的时候你会觉得莫名其

2016-03-18 23:45:15 194

原创 C | structure的size大小 和 OFFSETOF()

今天在geeksforgeeks(http://www.geeksforgeeks.org/the-offsetof-macro/)上面发现了一个自定义的Marco,如下:#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))用来求一个Element 在 Type 中的偏移量。其代码如下:#include

2016-03-16 04:52:10 346

原创 char a[] = "abc" 与 char* a = "abc"的区别

首先,C++中的存储区域有这么几个。以下内容转自:http://www.gotw.ca/gotw/009.htmThe following summarizes a C++ program's major distinct memory areas. Note that some of the names (e.g., "heap") do not appear as such in

2016-03-14 11:27:44 1650

转载 Scant的用法

Scansets in Cscanf family functions support scanset specifiers which are represented by %[]. Inside scanset, we can specify single character or range of characters. While processing scanset, s

2016-03-14 10:10:48 891

翻译 C | Storage Classes and Type Qualifiers | Question 6

原文链接:http://geeksquiz.com/c-storage-classes-and-type-qualifiers-question-6/考虑下列代码:#includeint main(){ typedef static int *i; int j; i a = &j; printf("%d", *a); return 0;}这个编译的时候会报错,

2016-03-14 09:26:31 132

原创 C/C++ 如何遍历目录下的所有文件夹

这篇文章参考了:http://sodino.com/2015/03/09/c-directory-io/#d_scanC/C++中如何打开目录:DIR *opendir(const char *name);opendir()函数打开一个指定路径name的文件夹关联的流,并将该流以执行结果的方式返回给调用者。在默认情况下,该流指向文件夹下的第一个目录。读取文件夹中的内容:

2016-03-02 00:36:59 832

原创 LeetCode Power of Two | 补码小知识

对于二进制来说,原码指的就是这个数本身。反码(One's compliment)指的是 按位取反补码(Two's compliment)指的是 取反后加一一个数的负数,就是它的补码。另外一个小技巧,可以用n&(~n+1),即一个数 和它本身的补码 做与运算,来提取第一个是1的bit位。所以可以简易的记成n&(-n)。Given an integer, write a

2016-02-14 08:57:20 155

原创 c++ 使用new时如何传递initializer

p = new T[N] {initializer1, ..., initializerN};这是C++11中用new来申请一块数组时候的语法。后面的{}中可以传递参数,从而调用不同的constructor;考虑下列代码;struct Workshops { int start; int end; int duration; Workshops(int

2016-02-10 05:26:43 208

原创 C++ 虚函数 小例子

考虑下列代码,class Animal {private:    std::string m_strName;protected:    Animal(const std::string& strName): m_strName(strName){}public:    const std::string& GetName() { ret

2016-02-05 04:27:52 170

原创 c++ virtual destructor 和 virtual function的关系。。

关于virtual function的作用我就不再赘述了。总之,就是让子类可以重新定义一个和基类同名的函数,并且不用考虑会把基类的覆盖掉。我原先以为 virtual destructor根virtual function一样,就是如果你不加virtual的话,那么derived class中的destructor就会把base class给覆盖了,结果发现,你不加virtual的话,根

2016-02-05 00:49:54 234

原创 Recover Binary Search Tree | LeetCode

Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.binary search tree的特点就是,中序遍历完了之后是一个increasing sequence。 比如一个binary search tr

2016-02-04 13:06:55 155

原创 C++中的const pointer, const int* p 和 int * const p 的区别

1. const int *p 和 int const *p首先,考虑const int *p, 首先,我们知道p是一个指针,然后考虑*前面的const int, 说明这个指针,指向的是一个const int 的类型,这说明什么, const int 的object是不可以改变内容的。所以const int *p 所指向的内容不可改变。同样的道理,再来考虑int const *p, 还是先

2016-02-04 11:41:58 529

原创 C++ int *p[4], int (*p)[4] 以及函数指针

第一个int *p[4]是一个指针数组。从优先级上考虑,[]的优先级大于*。所以创建出来的现实一个p[4],一个array,然后int* 作为辅助参数,array里面存的每一个都是一个int *再考虑 int (*p)[4]。这次的优先级,先是 *,所以先创建了一个指针出来,p, p指向的是一个int array. C++中函数指

2016-02-04 10:05:36 467

转载 MaxHeap & MinHeap 简单易懂的介绍

看面经的时候看到了特么要手动实现最大堆和最小堆。我就赶紧上网搜了搜,发现这篇特别好。这里转载一下:http://www.cnblogs.com/skywang12345/p/3610187.html以最大堆为例,最大堆的特点为[性质一] 堆中任意节点的值总是不小于其子节点的值;[性质二] 堆总是一棵完全树。下面是例子,因为是完全树,所以堆完全可以由数组来表示(01) 索引为i的

2016-01-13 04:29:38 1041

原创 Count of Range Sum | LeetCode

Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j),

2016-01-12 02:06:29 167

原创 Fraction to Recurring Decimal | LeetCode

166. Fraction to Recurring DecimalQuestionTotal Accepted: 24549 Total Submissions: 172168 Difficulty: MediumGiven two integers representing the numerator and denominator of a fra

2016-01-11 10:01:17 139

原创 C++ Mutex & Conditional variable

Mutex和Lock在多线程编程的时候,为了防止线程之间的干扰。我们需要用到锁。C++中,没有semaphor,我们可以用标准库提供的Mutex来完成。 考虑一下代码。两个线程1和2都先用mut.lock()来取得mutex,再对其上锁,进行操作,最后解锁。这样防止了两个线程互相干扰。#include Mutex mut;void func1() {mut.lock();/

2016-01-10 12:56:05 588

原创 c++ threads synchronization

院士说Nvidia面到threads了,我赶紧来临阵磨个枪。首先不像C,C++是没有semaphore的。。。只能用Mutex和Conditional variable来模拟。这里顺便复习一下OS学过的Mutex,Conditional Variable 和 semaphore. 1. (C)Semaphore可以理解成用一个变量来存储现有的resource数量。每一个semahor都有两

2016-01-10 11:49:05 191

原创 324. Wiggle Sort II | LeetCode

Given an unsorted array nums, reorder it such that nums[0] nums[2] .Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1, 3, 2, 2, 3

2016-01-09 05:09:17 517

原创 Read N Characters Given Read4 (1 && 2) | LeetCode

先说1;The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters l

2016-01-08 05:49:14 129

原创 282. Expression Add Operators | Leetcode

Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.

2016-01-07 10:50:00 207

原创 320. Generalized Abbreviation || Leetcode

Write a function to generate the generalized abbreviations of a word.Example:Given word = "word", return the following list (order does not matter):["word", "1ord", "w1rd", "wo1d", "

2016-01-05 13:04:39 1654

原创 Number of Islands II | LeetCode

Number of Islands IIMy SubmissionsQuestionTotal Accepted: 1666 Total Submissions: 5588 Difficulty: HardA 2d grid map of m rows and n columns is initially filled with water. W

2015-12-15 04:32:24 195

原创 Burst Balloons | LeetCode

Burst BalloonsMy SubmissionsQuestionTotal Accepted: 2119 Total Submissions: 7425 Difficulty: HardGiven n balloons, indexed from 0 to n-1. Each balloon is painted with a numbe

2015-12-15 01:32:59 368

原创 Binary Tree Vertical Order Traversal | Leetcode

Binary Tree Vertical Order TraversalMy SubmissionsQuestionTotal Accepted: 649 Total Submissions: 2309 Difficulty: MediumGiven a binary tree, return the vertical order traversal

2015-12-14 12:48:07 766

原创 K frequent words (in/not in stream) | lintcode

Top K Frequent WordsGiven a list of words and an integer k, return the top k frequent words in the list.Have you met this question in a real interview? YesExample

2015-12-14 06:03:41 301

原创 2 SUM | Leetcode

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, whe

2015-12-13 04:14:04 157

原创 Sliding Window Maximum | LeetCode

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window m

2015-11-30 11:10:21 166

原创 Factor Combination | LeetCode

Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4.Write a function that takes an integer n and return all possible combinations of its factors. Note: 

2015-11-30 02:48:31 221

原创 Patin House II | Leetcode

There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two ad

2015-11-30 00:40:01 224

原创 Palindrome Permutation II | Leetcode

Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.For example:Given s = "aabb", return ["

2015-11-29 13:26:50 173

原创 Additive Number | Leetcode

Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the

2015-11-28 01:00:07 138

翻译 Best Time to Buy and Sell Stock with Cooldow

Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on

2015-11-27 04:31:39 143

原创 Word Break II

Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "

2015-11-22 02:24:55 122

原创 Longest Substring with at most two distinct characters

Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3.因为最多只能有两个不一样的

2015-11-18 05:28:38 125

原创 Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o

2015-11-18 00:30:38 114

原创 Find Median from Data Stream Leetcode

Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median

2015-11-17 06:01:39 200

空空如也

空空如也

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

TA关注的人

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