- 博客(130)
- 资源 (5)
- 收藏
- 关注

转载 链表和数组的区别
构建: 数组必须事先定义固定的长度(元素个数),不能适应数据动态地增减的情况。当数据增加时,可能超出原先定义的元素个数;当数据减少时,造成内存浪费;数组可以根据下标直接存取。 链表动态地进行存储分配,可以适应数据动态地增减的情况,且可以方便地插入、删除数据项。(数组中插入、删除数据项时,需要移动其它数据项,非常繁琐)链表必须根据next指针找到下一个元素存储: 数组中的数据在
2015-05-04 13:39:18
883

转载 堆和栈的区别
一 、预备知识—程序的内存分配一个由C/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)—— 由编译器自动分配释放,存放函数的参数值,局部变量的值等。其 操作方式类似于数据结构中的栈。 2、堆区(heap)——一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回 收。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表。 3、全局区(静态区)(st
2015-05-04 13:38:51
455
转载 电脑上使环境变量立即生效的方法
电脑上使环境变量立即生效的方法我的电脑>属性>高级>环境变量,添加新环境变量或修改已有的环境变量运行“DOS命令提示符”或run cmd,假设要修改PATH变量,不管PATH的原值是什么,在DOS窗口直接把PATH修改为任意值,关闭DOS窗口,这时,我的电脑>属性>高级>环境变量里PATH已经在Windows全局生效了。不用担心在DOS窗口的修改会影响我的电脑>属性>高级>环境变量里的修改,D
2015-09-17 09:14:03
965
转载 线程和进程
1.定义进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位.线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如程序计数器,一组寄存器和栈),但是它可与同属一个进程的其他的线程共享进程所拥有的全部资源.2.关系 一个线程可以创建和撤销另一个线
2015-08-11 20:49:38
488
转载 快速排序
面试必备:#include <string>#include <iostream>#include <stdio.h>using namespace std;void print(int a[], int n){ for(int j= 0; j<n; j++){ cout<<a[j] <<" "; } cout<<endl;}void quickS
2015-08-11 19:36:02
443
转载 【leetcode】Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue. pop() – Removes the element from in front of queue. peek() – Get the front element. empty()
2015-08-02 16:37:16
369
转载 Static变量和一般变量的区别
1. static的作用,和一般定义的全局变量的区别全局变量(外部变量)的说明之前再冠以static 就构成了静态的全局变量。全局变量本身就是静态存储方式, 静态全局变量当然也是静态存储方式。 这两者在存储方式上并无不同。 这两者的区别在于非静态全局变量的作用域是整个源程序, 当一个源程序由多个源文件组成时,非静态的全局变量在各个源文件中都是有效的。 而静态全局变量则限制了其作用域, 即只在定义该
2015-07-27 15:07:10
572
原创 【leetcode】Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search Tree
2015-07-19 20:31:13
376
原创 【leetcode】Contains Duplicate II
Contains Duplicate IIGiven an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand
2015-06-04 21:14:06
489
原创 【leetcode】Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search Tree思路: 可以参考下Convert Sorted Array to Binary Search Tree。但是list无法直接访问下标,需要进行一些处理,可以通过自下到顶的方式来写。注意的是: 函数传递参数为ListNode* &head (仅存在在函数的传递参数中), 表示函数结束之后,head的修改之仍有效,而L
2015-06-02 22:12:02
401
原创 【leetcode】Subsets 1&2
SubsetsGiven a set of distinct integers, nums, return all possible subsets. Note: • Elements in a subset must be in non-descending order. • The solution set must not contain duplicate subsets.
2015-06-02 20:02:19
498
原创 【leetcode】Jump Game II
Jump Game IIGiven an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your
2015-05-26 00:07:36
370
原创 【leetcode】Count and Say
Count and SayThe count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off
2015-05-25 21:01:24
406
原创 【leetcode】Rotate List
Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 需要注意的几点: 1)求链表长度的时候,千万注意是w
2015-05-25 20:26:07
349
原创 【leetcode】Contains Duplicate
Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if
2015-05-25 19:35:37
375
原创 【leetcode】Letter Combinations of a Phone Number
Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) i
2015-05-25 00:09:20
345
原创 【leetcode】Longest Common Prefix
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings. 思路: 1)找到最短的字符串,因为最长子串不会比这个长; 2)一个一个字符比较,直到有不同的,退出,输出resclass Solution {public: string
2015-05-24 19:53:57
334
原创 【leetcode】House Robber II
House Robber IINote: This is an extension of House Robber. After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attentio
2015-05-24 17:43:56
337
原创 【leetcode】Longest Consecutive Sequence
Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elem
2015-05-24 16:58:12
376
原创 【leetcode】Reverse Linked List II
Reverse Linked List IIReverse 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
2015-05-19 15:49:58
375
原创 【leetcode】Multiply Strings
Multiply StringsGiven two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 思路: 给定两个字符串的数字,进行相乘,然后输出结
2015-05-18 21:35:50
346
原创 【leetcode】Permutation Sequence
Permutation SequenceThe set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): 1. “123”
2015-05-18 20:30:41
343
原创 【leetcode】Sqrt(x)
Sqrt(x)Implement int sqrt(int x). Compute and return the square root of x. 思路: 如果不知道二分之后左右的取法的话,可以找个实例进行推测。class Solution {public: int mySqrt(int x) { if(x<=1) return x; int lef
2015-05-18 19:21:47
389
转载 vetor, list, map, set的区别
List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]。 Vector对于随机访问的速度很快,但是对于插入尤其是在头部插入元素速度很慢,在尾部插入速度很快。List对于随机访问速度慢得多,因为可能要遍历整个链表才能做到,但是对于插入就快的多了,不需要拷贝和移动数据,只需要改变指
2015-05-18 18:47:04
663
原创 【leetcode】Combination Sum II
Combination Sum IIGiven a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once i
2015-05-18 18:45:53
369
原创 【leetcode】Combination Sum
Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unli
2015-05-17 21:14:39
346
原创 【leetcode】Insertion Sort List
Insertion Sort ListSort a linked list using insertion sort. 思路: 其实这个就是一一比较,不过需要记录插入排序之前的节点和之后的节点,用四个节点来记录各个节点。特别注意对头节点的处理。/** * Definition for singly-linked list. * struct ListNode { * int val
2015-05-17 20:31:34
415
原创 【leetcode】Path Sum II
Path Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example: Given the below binary tree and sum = 22, Return 思路: 用全局变量来记录r
2015-05-17 19:27:59
368
原创 【leetcode】Pow(x, n)
Pow(x, n)Implement pow(x, n). 思路: 思路就是递归,用简单递归的方法是O(n)的复杂度,但是如果二分之后再递归,复杂度为O(lg(n))。但是一定注意leetcode有个极限值-2147483648,如果要直接计算的话,就直接会出现无解的case,因此,需要把子函数的传递函数建立为long long形式。class Solution {public: do
2015-05-15 20:56:44
324
原创 【leetcode】Partition List
Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes
2015-05-15 20:27:25
322
原创 【leetcode】Unique Paths II
Unique Paths II Follow up for “Unique Paths”: Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectiv
2015-05-15 19:38:47
336
10个经典的Android开源项目(附源码包)
2012-03-15
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人