自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(21)
  • 资源 (6)
  • 收藏
  • 关注

原创 Leetcode 49. Group Anagrams

题意 将相同字母组成的字符串组成一组 题解 对每个字符串排序后在map中查找是否有相同的 代码class Solution { public: vector<vector<string> > groupAnagrams(vector<string>& strs) { vector<vector<string> > result; int index =

2016-03-30 21:50:31 259

原创 Leetcode 48. Rotate Image

题意 将数组顺时针旋转90度 题解 将结果保存在一个临时数组中,旋转对应关系为:temp[j][m - 1 - i] = matrix[i][j]; 代码“`c++ class Solution { public: void rotate(vector

2016-03-30 21:28:53 194

原创 Leetcode 47. Permutations II

题意 生成一个数组的全排列,去除重复的排列数组 题解 用递归实现。每个位置的数字都能和它后面的所有数字交换的,一共有n!种。用set去重超时,需要在递归中剪枝。如果交换中两个数的中间有一个数和后面的交换数相同(说明已经生成过此种排列),则停止生成此种排列。 代码class Solution { public: vector<vector<int> > result; bool

2016-03-28 21:46:07 1008

原创 Leetcode 46. Permutations

题意 生成一个数组的全派别 题解 用递归实现。每个位置的数字都能和它后面的所有数字交换的,一共有n!种。 代码class Solution { public: vector<vector<int> > result; void gen_permutation(int pos, vector<int> &nums) { if(pos == nums.si

2016-03-28 21:25:48 193

原创 Leetcode 43. Multiply StringsI

题意 用数字字符串模拟乘法。 题解 如题 代码class Solution { public: string mulStr(int digit, string num) { string result; int carry = 0; for (int i = num.length() - 1; i >= 0; i--)

2016-03-27 17:41:58 237

原创 Leetcode 40. Combination Sum II

题意 在候选集合C中选择数字(0个或1个),使它们的和为T。 题解 使用深度优先搜索。 代码class Solution { public: set<vector<int> > result; vector<int> temp; vector<vector<int>> combinationSum2(vector<int>& candidates, int targe

2016-03-26 21:23:24 242

原创 Leetcode 39 Combination Sum

题意 在候选集合C中选择数字(0个或多个),使它们的和为T。 题解 使用深度优先搜索。 参考:http://www.oschina.net/code/snippet_2399500_48909代码class Solution { public: vector<vector<int> > result; vector<int> temp; vector<vector<i

2016-03-25 20:15:27 203

原创 leetcode 38. Count and Say

题意 统计上个数字中的各个位,找到第n个数的表示字符串 例如:第一个数为“1”,则第二个数为1个1,即“11”,第三个数为2个1,“21”… 题解 如题 代码class Solution { public: string countPrev(string &num) { int len = num.length(); string resu

2016-03-24 21:28:43 230

原创 leetcode 35. Search Insert Position

题意 给一个有序数组,找插入位置 题解 找大于等于target的第一个数,使用自定义lower_bound的函数来查找插入位置 代码class Solution { public: int my_lower_bound(vector<int>& nums, int target) { int left = 0, right = nums.size() - 1;

2016-03-23 21:30:05 219

原创 leetcode 34. Search for a Range

题意 在有序数组中,找一个目标值的连续区间,不存在返回[-1, -1]。要求 时间复杂度为O(LogN) 题解 使用类似lower_bound,upper_bound的函数来二分查找。 lower_bound:查找第一个大于等于target的数 upper_bound:查找第一个大于target的数。 代码class Solution { public: int mylo

2016-03-20 11:30:53 215

原创 leetcode 31. Next Permutation

题意 生成比当前排列数大的下一个排列数(即字典序),没有则生成最小的字典序排列数。 题解 从后往前找两个相连且逆序排列的数(即nums[i] > nums[i - 1]),然后从i开始从前往后找一个大于nums[i-1]但最小的数,交换两数,然后将i之后的数排序就可得到下一个排列数。 代码class Solution { public: void printVec(vector<in

2016-03-15 22:38:07 210

原创 leetcode 30. Substring with Concatenation of All Words

题意 在串s中找一个连续的子串,要求words数组中的单词每个都要出现一次(重复的单词要多次出现),返回子串的起始下标 题解 用map保存单词及其出现的次数,然后枚举s的各个起始下标,找words中的各个单词。(如何找到单词且其剩余数目大于0,则继续查找下一个单词) 代码class Solution { public: vector<int> findSubstring(string

2016-03-14 21:55:18 369

原创 CSAPP Lab1--Manipulating Bits

/* * bitNor - ~(x|y) using only ~ and & * Example: bitNor(0x6, 0x5) = 0xFFFFFFF8 * Legal ops: ~ & * Max ops: 8 * Rating: 1 */ int bitNor(int x, int y) { return (~x)&(~y); }/* * bitXor

2016-03-11 17:50:18 3474

原创 CSAPP Lab2--Defusing a Binary Bomb

实验材料: GDB教程: http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/Debug.html http://www.gnu.org/software/gdb/ x86手册:https://sourceware.org/binutils/docs/as/ phase_2 //read_line读取到的字符串

2016-03-11 16:50:58 3256

原创 leetcode 29. Divide Two Integers

题意 在不使用乘、除、模运算的情况在进行除法运算 题解 每次将被除数拆分出能被除数除的最大值(是2^k形式)。 对应的位运算操作: 将除数左移直至是小于等于被除数的最大值,此时移位次数k表示: dividend >= divisor * 2^k。 例如:15/4 = 8/4 + 7/4 = 2 + 1 = 3; (4二进制为0100) 1) 第一次移动k=1位时8=10

2016-03-10 13:42:01 406

原创 leetcode 27. Remove Element

题意 求子串在字符串第一次出现的位置 题解 如题 代码class Solution { public: int strStr(string haystack, string needle) { int len = haystack.length(), sublen = needle.length(); if(sublen == 0)

2016-03-08 21:53:44 206

原创 leetcode 27. Remove Element

题意 除数组中值为val的元素 题解 如题 class Solution { public: int removeElement(vector<int>& nums, int val) { vector<int> temp; int len = nums.size(); for(int i = 0; i < len; i++)

2016-03-08 21:41:37 179

原创 leetcode 26. Remove Duplicates from Sorted Arra

题意 去除数组中重复的数 题解 用set来筛选不重复的数,然后保存在temp数组,然后复制给原数组 代码class Solution { public: int removeDuplicates(vector<int>& nums) { set<int> table; vector<int> temp; int len = nums.s

2016-03-08 21:35:53 174

原创 leetcode 25. Reverse Nodes in k-Group

题意 对链表上的每k个点进行一次转置。 题解 用头插法进行转置并用preNode记录转置前的第一个结点(即转置后的最后一个结点),然后用preNode连接转置后的各个子链表preNode->next = temphead->next;。 代码/** * Definition for singly-linked list. * struct ListNode { * int va

2016-03-08 15:57:39 231

原创 leetcode 24. Swap Nodes in Pairs

题意 交换链表相连两个点的值 题解 如题 代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution

2016-03-08 14:40:16 221

原创 leetcode 23. Merge k Sorted Lists

题意 合并k个有序链表为一个有序链表 题解 每次都比较k个列表头部当前第一个元素,找出一个最小的。可以想到使用堆这种数据结构删除一个最大或最小元素的时间复杂度是O(LogN)。C++的STL中用优先队列priority_queue实现了堆。 假设K个链表的元素个数都为N,则整体时间复杂度为O(NlogK) 代码/** * Definition for singly-linked li

2016-03-06 22:54:05 252

CSAPP Lab1:Manipulating Bits实验材料

《深入理解计算机系统》实验一(操作bit) 实验材料

2016-03-11

CSAPP Lab2: Defusing a Binary Bomb实验材料

《深入理解计算机系统》实验二--拆除二进制炸弹 实验材料

2016-03-11

CSAPP Lab 5:Writing a Dynamic Storage Allocator实验材料

《深入理解计算机系统》课程的实验5材料 解答过程在:http://blog.csdn.net/u010560443/article/details/50611251

2016-03-11

CSAPP实验5(二进制炸弹)材料

解答过程在:http://blog.csdn.net/u010560443/article/details/50857359

2016-03-11

CSAPP实验5(动态内存分配器)资料

CSAPP实验5(动态内存分配器)资料

2016-03-11

空空如也

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

TA关注的人

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