- 博客(238)
- 资源 (1)
- 收藏
- 关注
转载 字节序问题:大端还是小端
1. 大端字节序和小端字节序大端字节序:地址低位存储值的高位,地址高位存储值的低位;小端字节序:地址低位存储值的低位,地址高位存储值的高位;以数字:0x12345678为例,地址用相对地址,表示由低到高。big-Endian地址:01020304值:0x120x340x560x78
2017-07-06 20:00:27
653
原创 linux 命令: ps 和 top
ps命令提供进程的一次性查看,结果不是动态的;top对命令实时监控。1. psps命令只会显示运行在当前控制台下的属于当前用户的进程。UNIX风格 参数 描述 -A 显示所有进程 -a 显示除控制进程和终端进程外的所有进程 -d 显示除控制进程外的所有进程 -e 显示所有进程 -C cmdlist 显示包含在cmdlist列表中的进程 -G grpl
2017-07-06 16:13:17
1208
原创 625. Minimum Factorization
Given a positive integer a, find the smallest positive integer b whose multiplication of each digit equals to a.If there is no answer or the answer is not fit in 32-bit signed integer, then return
2017-06-21 15:17:42
880
转载 二叉树祖先
LCA,lowest common ancestor(二叉树祖先问题0找出两个节点的最低的公共祖先(LCA,lowest common ancestor)eg: _______3______ / \ ___5__ ___1__/ \ / \6 _2_ 0 8
2017-06-15 22:50:50
2688
原创 快速排序的稳定化实现
稳定排序的概念: 保证排序前2个相等的数其在序列的前后位置顺序和排序后它们两个的前后位置顺序相同。 例如:a[i]==a[j]&&i通常的快速排序为什么不稳定?快速排序初始的版本:int partition(vector<int>&a, int s, int e) { if (s < e) { int low = s, high = e, key = a[s];
2017-06-07 17:38:48
18373
10
原创 约瑟夫问题解答
问题: 编号为1,2,····n的n个人按顺时针做成一圈,一开始任选一个正整数作为报数的上限值m,从第一个人开始按顺时针方向自1开始顺时针报数,报到m时停止,这个人出列。从他在顺时针方向上的下一个人开始重新报数,如此下去,直至所有人出列。下面是用STL中的list#include <iostream>#include <list>#include <algorithm>using names
2017-05-30 21:38:00
715
原创 Array Nesting
A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].Sets S[K] for 0 <= K < N are defined as follows:S[K] = { A[K], A[A[K]], A[A[A
2017-05-28 21:19:27
1944
原创 字典序全排列递归总结:值传递与引用传递
问题:给定一个具有n个元素的集合(n>=1),要求输出这个集合中元素的所有可能的排列。 Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2],
2017-05-28 20:45:22
509
原创 AVL树的插入操作
AVL tree (Adelson-Velskii-Landis tree)一颗AVL树是其每个节点的左子树和右子树的高度最多差1的二叉查找树。加了额外的平衡条件是为了确保整棵树的深度为O(logN)在高度为h的AVL树,最少节点数S(h)=S(h-1)+S(h-2)+1.=========================================================
2017-05-20 20:58:28
1647
原创 STL 中list的常用接口
#include #include #include using namespace std;int main(){ list ilist; cout << "size= " << ilist.size() << endl; ilist.push_back(0); ilist.push_back(1); ilist.push_back(2); ilist.push_bac
2017-05-18 22:35:22
592
翻译 xv6—cha 0
操作系统接口:perating system interface interface features: simple and narrow; 接口:系统调用的集合 进程(process):each running program has memory containing instructions, data, and a stack. shell: an ordinary program
2017-05-13 20:27:00
952
原创 双向链表的基本操作
双向链表的建立,打印,查找,增删#include <iostream>#include <vector>#include <algorithm>#include <string>#include <climits>using namespace std;//以下是关于双链表的操作struct dnode { int data; dnode* left; dnod
2017-05-11 17:24:10
350
原创 单链表总结
#include <iostream>#include <vector>#include <string>using namespace std;void print(int a[], int n){ for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;}//直接插入排序void
2017-04-28 16:36:30
662
原创 排序总结
1. 直接插入排序//直接插入排序void insert_sort(int a[], int n){ int i, j, temp; for (i = 1; i < n; i++) { //暂存下标为i的数 temp = a[i]; //从后往前找要插入的位置 for (j = i - 1; j >= 0 &
2017-04-26 16:18:18
315
翻译 Longest Line of Consecutive One in Matrix
Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horizontal, vertical, diagonal or anti-diagonal.Example: Input: [[0,1,1,0], [0,1,1,0], [0,0,0,1]] O
2017-04-23 21:12:44
941
原创 有序数组和无序数组的二分查找
1. 有序数组的二分查找这种情况下,也是最经常的二分查找。 已知一个已经按递增(或递减)排好序的数组,想找到某个数值为k的元素。根据下标idx查找#include <iostream>#include <vector>#include <string>using namespace std;int binary_search(vector<int> & nums, int num) {
2017-04-22 10:33:37
2865
原创 TCP连接的握手和挥手
TCP握手:客户端发送一个SYN报文段(即一个在TCP头部的SYN位字段置位的TCP/IP数据包),并 指明自己想要连接的端口号和它的客户端初始序列号(记为x)。客户端发送的这个SYN报文段称为段1。服务器发送自己的SYN报文段作为响应,并包含它的初始序列号(记为y)。该段为段2。此外,为确认客户端的SYN,服务器将其包含的x+1后作为返回的ACK数值。因此,每发送一个SYN,序列号就会自动加
2017-04-19 22:19:01
651
原创 vector的内存管理
vector和string中有关容器大小管理的操作:c.capacity();//不重新分配内存空间的话,c可以保存多少元素c.reserve(n);//分配至少能容纳n个元素的内存空间c.shrink_to_fit();//将capacity()减小为与size()相同大小,不保证一定退回内存空间 c.resize();//调整c的大小为n个元素。若n<c.size(),则
2017-04-19 17:13:25
730
原创 自定义String类
//一个自建的MyString类#include <iostream>#include <cstring>using namespace std;class String{ private: char * str; int len; static int num_strings;//number of objects; publ
2017-03-25 13:32:15
546
原创 360笔试遇到的博弈问题(DP)
昨天,第一次参加找工作的笔试,最后一道编程题,总觉得很熟悉,但是没有做出来。以后,有时间记录下遇到的问题,便于以后看看。 题目是360公司的,大概讲的是两队海盗分金子,每次只能从一端取(左或者右),假设每队都按照最优的策略,问最后各取多少金子。 以前在LeetCode里也碰到过类似做游戏的问题,464. can I win,486. Predict the Winner。事后,发现这个题目和48
2017-03-19 10:27:03
1204
转载 C语言printf()函数:格式
转载于C语言中文网 头文件:#include #include<stdio.h>int main(void){ int a=1; float b=5.0; char str[100]= ""; scanf("%c %c %c",&a,&b,str); /*分别演示 整数*/ printf("int is:%d\n",a); /*分别演示
2017-03-14 19:30:05
733
原创 536. Construct Binary Tree from String
You need to construct a binary tree from a string consisting of parenthesis and integers.The whole input represents a binary tree. It contains an integer followed by zero, one or two pairs of parenthes
2017-03-12 14:29:23
635
原创 181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+--------+-----------+| Id | Name | Salary |
2017-03-06 10:53:11
489
转载 循环链表的判断
重新理解了快慢指针,判断是否有循环这一问题。 142. Linked List Cycle II 287. Find the Duplicate Number 先看第一个:判断循环链表 Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do
2017-03-04 21:28:30
1735
原创 183. Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.Table: Customers.+----+-------+| Id | Na
2017-03-04 16:35:42
375
转载 175. Combine Two Tables
Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+Per
2017-03-04 14:16:02
578
转载 Ubuntu 安装 mysql
转载出处:点击打开链接1. sudo apt-get update 装前更新2. sudo apt-get install mysql-server3. sudo apt-get install mysql-client4. sudo apt-get install libmysqlclient-dev验证是否成功:sudo netstat -tap | grep mys
2017-03-02 10:02:07
268
原创 221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0
2017-03-01 21:59:59
260
转载 115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non
2017-02-27 22:23:59
387
原创 529. Minesweeper
Let's play the minesweeper game (Wikipedia, online game)!You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' represents an unrevealed empty squar
2017-02-26 14:51:00
936
1
原创 97. Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return false
2017-02-25 21:51:39
299
原创 304. Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).The above rectangle (with the red bo
2017-02-25 16:15:54
381
翻译 220. Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference b
2017-02-24 22:01:59
283
翻译 222. Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and
2017-02-23 22:25:06
314
原创 从求逆序对和mergeSort谈起(3)
Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion coun
2017-02-23 09:59:57
471
原创 从求逆序对和mergeSort谈起(2)
应用mergeSort的思想,可以解决许多和下标有关的问题。看了有关题的提示,发现有些能用Divide and Conqure解决的,也可以用 Binary Search Tree,Segment Tree,Binary Index Tree解决。它们都可以把原始的时间复杂度为O(n2)O(n^2)的算法降低为O(nlogn)O(nlogn). 下面从求数组的逆序数对这一问题,用不同的方法去解决。
2017-02-21 18:51:08
421
原创 从求逆序对和mergeSort谈起
先来谈谈mergeSort, 它是排序算法的一种,核心思想是:对一个数组nums[0,…,n],首先把它分成两部分nums[0,…,mid]和nums[mid+1,…,n],首先两个子数组是排好序的,只要对两个子数组进行整合,然后就排好序了,但是我们可以在对数组整合的时候,作好多事情,。。。 根据主定理,T(0,n)=T(0,(n-1)/2)+T((n-1)/2,n)+C, 其中C是合并时的时间复
2017-02-20 22:30:03
589
转载 307. Range Sum Query - Mutable.
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i to val.Examp
2017-02-17 10:49:48
347
转载 segment tree(线段树)
简介 线段树(segment tree)是一种存储区间的树形结构,方便查询哪一个区间包含了指定的点,原则上,它是一种固定结构,一旦建成该树,它的结构不会改变。对于n个区间的集合,建一棵线段树的时间复杂度和空间复杂度都是O(nlgn)。2. 定义一维线段树结构:假设有一个区间集合,每一个区间元素从左到右依次是:。步骤:ste
2017-02-16 21:56:51
965
转载 381. Insert Delete GetRandom O(1) - Duplicates allowed
Design a data structure that supports all following operations in average O(1) time.Note: Duplicate elements are allowed.insert(val): Inserts an item val to the collection.remove(val): Remov
2017-02-16 09:57:32
345
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人