
基础篇
姥姥教我学编程
Linux爱好者、算法爱好者
展开
-
数据结构篇—姥姥教我学编程系列
数据结构篇—姥姥教我学编程系列原创 2013-09-21 21:25:11 · 1776 阅读 · 0 评论 -
c/c++内存区域
C语言变量声明及内存分配一个由c/C++编译的程序占用的内存分为以下几个部分1、栈区(stack)— 程序运行时由编译器自动分配,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。程序结束时由编译器自动释放。2、堆区(heap) — 在内存开辟另一块存储区域。一般由程序员分配释放,若程序员不释放,程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事,分配方式倒是类原创 2013-11-19 17:34:55 · 969 阅读 · 0 评论 -
printf函数的简单模拟实现
#include #include #include using namespace std;void printlog(const char * str, ...){ int vint; char *vstr; char vch; char num[10]; char buff[256]; memset(buff, 0, sizeof(buff)); va_l原创 2013-11-23 14:20:45 · 912 阅读 · 0 评论 -
关于typedef的用法总结
不管实在C还是C++代码中,typedef这个词都不少见,当然出现频率较高的还是在C代码中。typedef与#define有些相似,但更多的是不同,特别是在一些复杂的用法上,就完全不同了,看了网上一些C/C++的学习者的博客,其中有一篇关于typedef的总结还是很不错,由于总结的很好,我就不加修改的引用过来了,以下是引用的内容(红色部分是我自己写的内容)。用途一:定义一种类型的别名,而不转载 2013-11-23 17:46:24 · 570 阅读 · 0 评论 -
参数个数可变函数浅析
C语言参数个数可变函数浅析VA函数(variable argument function),参数个数可变函数,又称可变参数函数。C/C++编程中,系统提供给编程人员的va函数很少。*printf()/*scanf()系列函数,用于输入输出时格式化字符串;exec*()系列函数,用于在程序中执行外部文件(main(int argc,char*argv[])算不算呢,与其说main()也是一个可变转载 2013-11-23 13:19:30 · 844 阅读 · 0 评论 -
结构体的强制类型转化(android中的代码问题)
分析一下结构体的强制类型转化,远离不太冻#include "stdafx.h"struct hw_device_t{int open;};struct hw_hello_t{ struct hw_device_t common;int x;int y;};void open_device(struct hw_device_t *原创 2013-11-22 20:50:14 · 972 阅读 · 0 评论 -
美丽心灵的终极分析
一个精神分裂症患者的传奇 即使是现在,当人们谈到精神分裂症患者时,通常的反应仍是感到恐惧、不可思议和排斥、歧视,生活在真实社会、普通生活中的正常人是很难理解精神病患者的那些怪异行为和举止的。可是在我们的社会中,精神病人却是越来越多了,他们不仅需要得到医生和心理工作者的关注,还需要得到大众的认可和支持。 《美丽心灵》的编剧阿基瓦·戈尔兹曼对剧情作了精心安排,男主角纳斯的扮演者罗素转载 2013-12-01 19:50:53 · 1337 阅读 · 0 评论 -
动手和总结
做得多,不一定总结得好,因为可能越多越杂,总结起来越麻烦。如果你总结不好,在老板看来,你可能做得一塌糊涂。 做得少,不一定说不好,做得少思路简单,总结起来相对轻松很多。一个思路清晰的,比一个只懂蛮干苦干的,给人的映像更好。 所以做得多就错了吗,我们好奇问题的真相,对问题孜孜以求,是内心的驱使。做得多,学到的会更多,见识会更多。但同时见到的越多,迷茫也越多,心境也原创 2013-12-03 10:48:47 · 624 阅读 · 1 评论 -
extern "C"的用法解析
1.引言 C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同。作为一种欲与C兼容的语言,C++保留了一部分过程式语言的特点(被世人称为“不彻底地面向对象”),因而它可以定义不属于任何类的全局变量和函数。但是,C++毕竟是一种面向对象的程序设计语言,为了支持函数的重载,C++对全局函数的处转载 2013-12-02 16:05:30 · 489 阅读 · 0 评论 -
git 拉取远程分之到本地
git 拉取远程分之到本地git checkout -b newbranch_name --track origin/feature/newbranch_name 如果遇到类似:fatal: git checkout: updating paths is incompatible with switching branches.Did you intend to checko原创 2013-12-28 09:49:18 · 1582 阅读 · 0 评论 -
LeetCode OJ - N-Queens 回溯法
回溯算法 http://blog.youkuaiyun.com/shuilan0066/article/details/7702737The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given a原创 2014-04-27 19:30:12 · 719 阅读 · 0 评论 -
各种排序算法分析比较
先研究典型的吧,归并与paixu原创 2014-04-20 17:51:48 · 575 阅读 · 0 评论 -
LeetCode OJ - LRU Cache
LRU Cache 缓存替换策略的一种,最近最少使用;还可以是用随机替换策略。本身貌似不难原创 2014-05-06 16:18:33 · 763 阅读 · 0 评论 -
STL中map用法详解
Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后边我们会见识到有原创 2014-04-20 14:08:23 · 423 阅读 · 0 评论 -
动态规划与贪心算法
动态规划的实质是分治思想和解决冗余,因此,动态规划是一种将问题实例分解为更小的、相似的子问题,并存储子问题的解而避免计算重复的子问题,以解决最优化问题的算法策略。原创 2014-04-23 10:37:08 · 794 阅读 · 0 评论 -
LeetCode OJ - 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原创 2014-05-15 09:09:27 · 593 阅读 · 0 评论 -
LeetCode OJ - Linked List Cycle I and II 初中数学解释
写解法证明,网上好多代码,弄了半天才理解两个点:1.相遇点Z 2.相遇后,fast留在Z点,slow留在头节点X点,一起走,最后它们在环开始节点Y点相遇。解释:设slow的速度为v,fast的速度为2v,经历时间t(单位一步)。A.在Z点相遇可以得到(2v - v)t = n (b + c) 其中n为正整数。 由此得出vt = n(b + c) = (a原创 2014-04-24 21:36:45 · 650 阅读 · 0 评论 -
由LeetCode想到算法中的<横向思维和纵向思维>:
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2014-04-24 10:58:22 · 886 阅读 · 0 评论 -
LeetCode OJ - Binary Tree Preorder Traversal
Binary Tree Preorder Traversal Total Accepted: 17759 Total Submissions: 51092My SubmissionsGiven a binary tree, return the preorder traversal of its nodes' values.For example:Given b原创 2014-05-11 20:57:28 · 657 阅读 · 0 评论 -
LeetCode OJ - Binary Tree Postorder Traversal
后序遍历二叉树,基础题。采用递归和非递归两种方式:原创 2014-05-11 20:31:44 · 540 阅读 · 0 评论 -
LeetCode OJ - Reverse Integer
整型溢出问题,《深入理解计算机系统》有原创 2014-04-26 12:42:45 · 479 阅读 · 0 评论 -
LeetCode OJ - Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"原创 2014-05-15 09:18:00 · 475 阅读 · 0 评论 -
LeetCode OJ - 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 = "原创 2014-05-19 12:03:52 · 527 阅读 · 0 评论 -
图的BFS与DFS
存储结构原创 2014-05-26 11:46:32 · 532 阅读 · 0 评论 -
LeetCode OJ - Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on原创 2014-05-21 14:49:21 · 679 阅读 · 0 评论 -
LeetCode OJ - Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea原创 2014-05-25 15:23:51 · 597 阅读 · 0 评论 -
金矿模型之DP学习
http://www.cnblogs.com/sdjl/articles/1274312.html分析:采用作者介绍原创 2014-05-21 16:02:56 · 947 阅读 · 0 评论 -
LeetCode OJ -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, whe原创 2014-06-21 17:29:34 · 731 阅读 · 0 评论 -
LeetCode OJ - Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-06-23 18:34:38 · 479 阅读 · 0 评论 -
LeetCode OJ - Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2014-07-15 15:31:43 · 529 阅读 · 0 评论 -
解决方案与需求 (写得相当好)
曾经有一个很有名的段子,大致意思就是说在汽车尚未出现的马车时代,你去做消费者调研,只会得到这样的答案:我需要一匹更快的马,而不会得到:我需要汽车。因为对于消费者来说,他从来没有看到过汽车,怎么可能回答你需要汽车呢?这个段子,似乎充分说明了,创新,尤其是颠覆式创新、破坏性创新是不可能通过需求调研出来的。不过,拿这个段子说事可能是有些问题的。说的人没有搞清楚一点,到底什么叫需求。在“我需要一匹转载 2013-12-27 17:50:42 · 1542 阅读 · 0 评论 -
LeetCode OJ - Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-06-23 23:09:35 · 546 阅读 · 0 评论 -
LeetCode OJ - 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->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t原创 2014-06-22 18:57:58 · 590 阅读 · 0 评论 -
递归转化为非递归的一般方法
转载递归的本质是通过栈来保存状态,然后再次调用自己进入新的状态,然后函数返回的时候回到上次保存的状态。尾递归可以直接转化成循环,这里不多做分析更一般的递归,想要转化为非递归,就需要模拟栈的行为。 首先需要自己建个栈。栈保存的东西是一个记录,包括所有局部变量的值,执行到的代码位置。首先讲局部变量初始化位一开始的状态,然后进入一个循环转载 2014-07-15 22:45:47 · 1584 阅读 · 0 评论 -
LeetCode OJ - 3Sum、3Sum Closest、4Sum
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原创 2014-06-23 13:22:14 · 724 阅读 · 0 评论 -
LeetCode OJ - Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th原创 2014-06-25 09:18:37 · 605 阅读 · 0 评论 -
LeetCode OJ - Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis原创 2014-06-25 09:21:03 · 594 阅读 · 0 评论 -
LeetCode OJ - Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-06-24 11:02:16 · 557 阅读 · 0 评论 -
LeetCode OJ - Partition List
思路原创 2014-07-17 13:40:14 · 515 阅读 · 0 评论 -
LeetCode OJ - Search a 2D Matrix
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo原创 2014-07-17 16:34:03 · 541 阅读 · 0 评论