自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(38)
  • 资源 (2)
  • 收藏
  • 关注

原创 leetcode 22. Generate Parentheses

题目要求:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()"

2017-04-06 16:56:56 215

原创 leetcode 51. N-Queens

题目链接:点击打开链接题目:The n-queens puzzle is the problem of placing n queens on ann×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to

2017-03-28 22:40:01 218

原创 50. Pow(x, n)

题目链接:点击打开链接题目:Implement pow(x,n).实现x的n次方思路:第一次采用了快速幂的方法,结果超时了。后来参考别人的答案,选择用递归解决。同时要特别处理n代码AC:public class Solution { public double myPow(double x, int n) { i

2017-03-27 22:12:11 191

原创 leetcode 129. Sum Root to Leaf Numbers

链接:点击打开链接题目:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number123.

2017-03-27 21:30:04 201

原创 leetcode Single Number II

题目:Given an array of integers, every element appearsthree times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime complexity

2017-03-27 16:34:21 180

原创 Java垃圾回收

一. 简介Java与C语言相比的一个优势是,可以通过自己的JVM自动分配和回收内存空间。垃圾回收机制是由垃圾收集器Garbage Collection来实现的,GC是后台一个低优先级的守护进程。在内存中低到一定限度时才会自动运行,因此垃圾回收的时间是不确定的。1、哪些“垃圾”需要回收?程序计数器、JVM栈、本地方法栈不需要进行垃圾回收

2017-03-25 22:03:48 207

原创 Java内存模型

Java虚拟机会将内存分为几个不同的管理区,这些区域各自有各自的用途,根据不同的特点,承担不同的任务以及在垃圾回收时运用不同的算法。总体分为下面几个部分:程序计数器(Program Counter Register)、Java虚拟机栈(JVM Stack)、本地方法栈(Native Method Stack)、堆(Heap)、方法区(Method Area),如下图:1.

2017-03-25 21:51:12 177

原创 线程进程

1、 线程与进程的区别进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位。线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如程序计数器,一组寄存器和栈),但是它可与同属一个进程的其他的线程共享进程所拥有的全部资源。同一个进程

2017-03-25 21:36:59 154

原创 leetcode 113. Path Sum II Add to List

题目链接:https://leetcode.com/problems/path-sum-ii/#/description题目: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 b

2017-03-24 16:56:25 190

原创 LeetCode 112. Path Sum

题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.思路:用sum减去当前节点的值,直到遇到一个叶子节点,并且此时差值为0。在做题

2017-03-24 15:35:04 180

原创 合唱团(2016网易编程题)

题目:有 n 个学生站成一排,每个学生有一个能力值,牛牛想从这 n 个学生中按照顺序选取 k 名学生,要求相邻两个学生的位置编号的差不超过 d,使得这 k 个学生的能力值的乘积最大,你能返回最大的乘积吗?输入描述:每个输入包含 1 个测试用例。每个测试数据的第一行包含一个整数 n (1 i(-50 输出描述:输出一行表示最大的乘积。输入例子:

2017-03-23 10:13:04 4618

原创 背包问题

题目:给出n个物品的体积A[i]和其价值V[i],将他们装入一个大小为m的背包,最多能装入的总价值有多大?思路:采用动态规划法。V[N][W]表示到物品N在背包重量为W时的最大价值,则对于第i个物品,有两种情况:第一种情况是A[i] 1. 计算放入物品i背包的最大价值 V[i-1][w-A[i]]+V[i-1]2. 计算不放入物品i背包的最大价值 V[i

2017-03-22 13:24:07 212

原创 迅雷2016研发工程师5道笔试题

题目1、若串str="xunlei",其子串的数目是()子串: n(n+1)/2 + 1非空子串:n(n+1)/2非空真子串:n(n+1)/2 - 1所以子串的数量是22。题目2、若栈采用链式存储结构,则下列说法中正确的是()A、需要判断栈满但不需要判断栈空B、不需要判断栈满也不需要判断栈空C、需要判断栈满且需要判断栈空

2017-03-21 14:27:50 578

原创 京东2016研发工程师笔试题【年终奖】

题目:小东所在公司要发年终奖,而小东恰好获得了最高福利,他要在公司年会上参与一个抽奖游戏,游戏在一个6*6的棋盘上进行,上面放着36个价值不等的礼物,每个小的棋盘上面放置着一个礼物,他需要从左上角开始游戏,每次只能向下或者向右移动一步,到达右下角停止,一路上的格子里的礼物小东都能拿到,请设计一个算法使小东拿到价值最高的礼物。给定一个6*6的矩阵board,其中每个元素为对应格子的礼物价

2017-03-21 12:44:35 441

原创 leetcode 142. Linked List Cycle II

题目:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.给定一个链表,返回链表中环的第一个节点。思路:p1为环开始的节点,p2为fast指针和slow指针相遇的节点。A 、B、 C分别为三段的距离。当相遇的时候slow指针经过的

2017-03-20 22:01:44 152

原创 leetcode 141. Linked List Cycle

题目:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?判断一个单项链表是否有环。思路:使用两个指针slow,fast。两个指针都从表头开始走,slow每次走一步,fast每次走

2017-03-20 21:14:58 168

原创 冒泡排序BubbleSort

冒泡排序的原理:将临近的数字两两进行比较,按照从小到大或者从大到小的顺序进行交换,这样一趟过去后,最大或最小的数字被交换到了最后一位,然后再从头开始进行两两比较交换,直到倒数第二位时结束。代码实现: public void bubbleSort(int[] nums, int n){ int i = 0, j = 0; for(i =

2017-03-20 17:11:06 386

原创 leetcode 111. Minimum Depth of Binary Tree

题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.求二叉树的最小深度,二叉树的最小深度为根节点到最近叶子节点的距

2017-03-18 22:15:39 157

原创 寻找Coder(2015去哪儿校招笔试题)

题目:请设计一个高效算法,再给定的字符串数组中,找到包含"Coder"的字符串(不区分大小写),并将其作为一个新的数组返回。结果字符串的顺序按照"Coder"出现的次数递减排列,若两个串中"Coder"出现的次数相同,则保持他们在原数组中的位置关系。给定一个字符串数组A和它的大小n,请返回结果数组。保证原数组大小小于等于300,其中每个串的长度小于等于200。同时保

2017-03-18 21:33:32 260

原创 2016[编程题]裁减网格纸

题目:度度熊有一张网格纸,但是纸上有一些点过的点,每个点都在网格点上,若把网格看成一个坐标轴平行于网格线的坐标系的话,每个点可以用一对整数x,y来表示。度度熊必须沿着网格线画一个正方形,使所有点在正方形的内部或者边界。然后把这个正方形剪下来。问剪掉正方形的最小面积是多少。要求一个最小的正方形,使其能够包围所有的网格点。思路:遍历所有的点的坐标,记录最小的x,y 

2017-03-18 11:33:39 326

原创 leetcode 110.Balanced Binary Tree

题目:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofevery node never

2017-03-17 22:45:13 334

原创 leetcode 108. Convert Sorted Array to Binary Search Tree Add to List

题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.给定一个递增的数组,要求创建一棵二插查找树。思路:采用二分法,递归地进行创建。令中间节点为根,从而满足左子树的值小于根节点的值,同时右子树的值大于根节点的值。代码AC:

2017-03-17 21:55:24 152

原创 leetcode 107. Binary Tree Level Order Traversal II Add to List

题目:要求从左往右,从下往上层次遍历二叉树。代码AC:

2017-03-17 21:18:28 148

原创 leetcode 104. Maximum Depth of Binary Tree

题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.找到一棵二叉树的最大深度思路:采用递归的方法,分别找到

2017-03-17 10:34:19 361

原创 二分查找算法

二分查找算法是在有序数组中用到的较为频繁的一种算法,在未接触二分查找算法时,最通用的一种做法是,对数组进行遍历,跟每个元素进行比较,其时间为O(n)。但是二分查找算法更优,因为其查找时间为O(lgn),譬如数组{1, 2, 3, 4, 5, 6, 7, 8, 9},查找元素6,用二分查找的算法执行的话,其顺序为:    1.第一步查找中间元素,即5,由于5    2.寻找{6, 7, 8,

2017-03-17 09:48:26 179

转载 快速幂

快速幂的目的:做到快速求幂。假设我们要求a^b,按照朴素算法就是把a连乘b次,这样一来时间复杂度是O(b)也即是O(n)级别。如果n非常大时,就会超时。而快速幂的时间复杂度为O(logn)。快速幂的原理:假设我们要求a^b,其实b是可以拆成二进制的,该二进制数第i位的权为2^(i-1),例如当b==11时,11 = 2³×1 + 2²×0 + 2¹×1 + 2º×1,

2017-03-17 09:21:07 295

原创 leetcode 101. Symmetric Tree

题目:要求判断一棵二叉树是否对称思路:采用递归的办法,直接比较对称位置,即将left的left和right的right比较,left的right和right的left比较。时间复杂度为O(n)。代码AC:

2017-03-16 23:30:44 152

原创 leetcode 88. Merge Sorted Array

题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to h

2017-03-16 22:39:32 131

原创 leetcode 100. Same Tree

题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.判断两

2017-03-16 22:12:38 255

原创 leetcode 82. Remove Duplicates from Sorted List II

题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.要求把链表中所有重复

2017-03-16 16:05:38 426

原创 leetcode 83. Remove Duplicates from Sorted List

题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.将所有重复的元素从有序的链表中删除

2017-03-16 11:04:30 241

原创 搜狗2016研发工程师笔试(矩阵元素相乘)

题目:思路: 将A[i][j]所在行除了A[i][j]元素的其余元素之积与A[i][j]所在列除了A[i][j]元素的其余元素之积相乘,其中A[i][j]所在行除了A[i][j]元素的其余元素之积为A[i][j]后面元素之积与前面元素之积相乘,A[i][j]所在列除了A[i][j]元素的其余元素之积为A[i][j]上面元素之积与下面元素之积相乘。代码AC:

2017-03-15 22:59:41 269

原创 leetcode 238 Product of Array Except Self

题目:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].求一个数组中除了某个元素本身的其他元素之积,,最终输出所有这样

2017-03-15 21:24:07 182

原创 leetcode 136. Single Number

题目:Given an array of integers, every element appears twice except for one. Find that single one.找到在数组中只出现过一次的数,要求线性时间,同时空间复杂度为O(1)。思路:将数组中的元素从小到大进行排列,然后比较相邻的元素,判断相邻的元素是否相等。实现代码:另

2017-03-15 15:05:43 323

原创 leetcode 125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is no

2017-03-15 10:44:08 193

原创 二叉树遍历

二叉树的前序遍历:     1.访问根节点     2.前序遍历左子树     3.前序遍历右子树 二叉树的中序遍历:     1.中序遍历左子树     2.访问根节点     3.中序遍历右子树 二叉树的后序遍历:     1.后序遍历左子树     2.后序遍历右子树     3.访问根节点

2017-03-14 09:44:51 189

原创 leetcode 69. Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x.如果采用暴力破解法,从 0 到 x/2之间依次遍历,但是时间太慢,故选择考虑二分法。 public int mySqrt(int x) {             if(x       return x;

2017-03-13 16:23:27 172

转载 位运算基本操作总结

一:位运算基本操作知识点1. 左移操作 a 将A的二进制表示的每一位向左移B位,左边超出的位截掉,右边不足的位补0A = 1100  B = 2A 每左移一位,数值乘以2。2.右移操作 A >> B , A >>> B右移操作分为逻辑右移,和算术右移算术右移是带符号的右移,逻辑右移是不带符号的右移。算术右移:将A的二进

2017-03-13 10:28:32 278

nachos基于优先级的线程调度实验

线程数目不超过128,实现基于优先级的线程调度

2013-05-28

四川大学操作系统虚拟内存管理实验代码

四川大学虚拟内存管理实验代码,实现虚拟内存,并处理缺页中断

2013-05-25

空空如也

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

TA关注的人

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