- 博客(292)
- 资源 (4)
- 收藏
- 关注
原创 【Hackerrank】Reverse a doubly linked list
You’re given the pointer to the head node of a doubly linked list. Reverse the order of the nodes in the list. The head node might be NULL to indicate that the list is empty. Input Format You have t
2013-12-16 22:07:22
1262
原创 【Hackerrank】Insert a node into a sorted doubly linked list
You’re given the pointer to the head node of a sorted doubly linked list and an integer to insert into the list. The data in the nodes of the list are in ascending order. Create a node and insert it i
2013-12-16 16:43:50
1760
原创 【Hackerrank】Find the merge point of two joined linked lists
You’re given the pointer to the head nodes of two linked lists that merge together at some node. Find the node at which this merger happens. The two head nodes will be different and neither will be NU
2013-12-16 14:35:36
1104
原创 【Hackerrank】Delete duplicate-value nodes from a sorted linked list
You’re given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more t
2013-12-16 09:55:52
1600
原创 【Hackerrank】Get the value of the node at a specific position from the tail
You’re given the pointer to the head node of a linked list and a specific position. Counting backwards from the tail node of the linked list, get the value of the node at the given position. A positio
2013-12-16 09:08:04
1136
原创 【Hackerrank】Merge two sorted linked lists
This challenge is part of a tutorial track by MyCodeSchool You’re given the pointer to the head nodes of two sorted linked lists. The data in both lists will be sorted in ascending order. Change th
2013-12-13 20:13:03
1197
原创 【LeetCode】Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Note: Recursive solution is tri
2013-12-03 20:59:46
879
原创 【LeetCode】Insertion Sort List
Sort a linked list using insertion sort. java code: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val
2013-12-03 20:37:20
3189
原创 MapReduce 工作机制
本文主要内容 MapReduce作业的执行流程错误处理机制作业调度机制Shuffle和排序任务执行 1.MapReduce任务执行总流程 一个MapReduce作业的执行流程是:代码编程--->job configuration--->提交作业--->Mapper任务的分配执行--->处理中间结果--->Reduce任务分配执行--->完成。 如下图:(援引google 图片)
2013-11-29 17:38:32
1418
原创 浅谈Hadoop容错机制
简单介绍一下Hadoop中数据存储的可靠性和完整性,其中包括HDFS的容错机制、NameNode(元数据结点)的单点失效解决机制、Block数据块的多副本存储机制、 NameNode与DataNode之间的心跳检测机制、数据存储等。 (一)HDFS中NameNode单点问题 HDFS这种分布式的存储系统,存在中心结点,那么这个中心结点的可靠性就是整个集群的可靠性的关键,对于版本0.20.x的
2013-11-22 14:26:44
6740
原创 MapReduce 编程之 倒排索引
本文调试环境: ubuntu 10.04 , hadoop-1.0.2 hadoop装的是伪分布模式,就是只有一个节点,集namenode, datanode, jobtracker, tasktracker...于一体。 本文实现了简单的倒排索引,单词,文档路径,词频,重要的解释都会在代码注视中。 第一步,启动hadoop, 开发环境主要是用eclipse. 在本地文件系统中新建三个
2013-11-19 22:23:12
1916
原创 【LeetCode】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
2013-11-07 20:05:50
792
原创 【LeetCode】Combination Sum
Given 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 unlimited numb
2013-11-07 16:18:31
1224
原创 【LeetCode】Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [
2013-11-06 15:16:49
983
原创 【LeetCode】Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. Note: Recursive soluti
2013-11-06 14:01:41
2724
原创 【LeetCode】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 respectively in the
2013-11-05 15:50:15
2478
原创 【LeetCode】Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1].
2013-11-05 15:16:52
1017
原创 【LeetCode】Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible o
2013-11-04 13:24:03
2512
原创 【LeetCode】Longest Consecutive Sequence
Given 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 elements sequence is [1, 2, 3,
2013-11-04 11:03:00
984
原创 【LeetCode】Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. java code : /** * Definition for singly-linked list. * public class ListNode { *
2013-11-04 10:21:34
1063
原创 【LeetCode】 Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? 解法一: 哈希,需要O(n)的空间复杂度,时间复杂度是O(n) /**
2013-11-01 14:44:38
3172
2
原创 【LeetCode】 Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially fille
2013-10-31 18:58:26
1451
原创 【LeetCode】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, 5 / \
2013-10-31 14:36:39
1978
原创 【LeetCode】Jump Game (一维动态规划 + 线性扫描)
Given 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. Determine i
2013-10-30 15:23:10
7462
原创 【LeetCode】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? java code : 很简单的判断单链表是否有环。 /** * Definition for singly-linked list. * class
2013-10-29 22:21:57
2558
原创 【LeetCode】Trapping Rain Water 2013年美团网校园招聘研发工程师笔试题
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1],
2013-10-29 22:07:30
1233
原创 【LeetCode】Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. java code : 预处理出最短串与任意一字符串的公共前缀,用StringBuilder保存,再去遍历剩余字符串,从尾处开始推。 复杂度O(m * n) m : length of the arrays, n :le
2013-10-29 17:01:43
1002
原创 【LeetCode】 Subsets Subsets II
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets. For example,
2013-10-29 15:43:32
1321
原创 【LeetCode】Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return it
2013-10-27 13:06:58
1093
原创 【LeetCode】3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2013-10-27 10:48:49
1100
原创 【LeetCode OJ】Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all va
2013-10-26 20:35:41
922
原创 Java NIO 非阻塞式 C/S结构简易 多人聊天室
使用JAVA 的 NIO 实现了服务器端 / 客户端 结构的简易多人聊天室: 说明都在代码注释里了,希望可以不断完善 服务器端: import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.Channel; impor
2013-10-25 22:06:50
2455
原创 【LeetCode OJ】 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. cpp code : 暴力求解,递归到每一个叶子节点,记录深度,
2013-10-25 12:58:44
839
原创 【LeetCode OJ】Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]
2013-10-25 10:28:18
834
原创 Java 简易C/S结构多线程聊天室 (阻塞式)
主要实现的功能: 服务器端建立ServerSocket阻塞监听来自客户端的Socket连接,并为之开辟一个新的线程 读取来自该连接的数据,广播每一个客户端数据,这里简单地使用一个链表保存所有来自客户端的所有Socket连接 客户端连接上服务器端后主要有两个线程在工作: 主线程:不断获取键盘的输入并写入该Socket中传输给服务器 副线程:不断从服务器Socket流中读取传来的数据,打印到
2013-10-24 22:36:13
2817
原创 【LeetCode OJ】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 number 123. Find the tota
2013-10-24 14:14:45
2319
原创 Java 多线程下载
开发环境:win 7 (64 bit) + eclipse 还未实现断点下载,如需实现断点下载,则需要额外增加一个配置文件: import java.io.InputStream; import java.io.RandomAccessFile; import java.net.HttpURLConnection; import java.net.URL; public class
2013-10-23 19:48:04
886
原创 【LeetCode OJ】Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution using O(m
2013-10-22 18:52:42
1566
原创 【LeetCode OJ】Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extr
2013-10-22 13:09:41
1305
原创 【LeetCode OJ】Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using
2013-10-21 13:17:40
2701
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅