- 博客(671)
- 资源 (5)
- 收藏
- 关注
原创 Interleaving Positive and Negative Numbers
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers. NoticeYou are not necessary to keep the original order of positive intege
2017-11-18 20:14:07 211
原创 Kth Smallest Numbers in Unsorted Array(分别使用快排、归并、快选三种方法)
Find the kth smallest numbers in an unsorted integer array.Have you met this question in a real interview? Yes Example Given [3, 4, 1, 2, 5], k = 3, the 3rd smallest numbers are [1, 2, 3].快排public cl
2017-11-18 18:55:04 558
原创 139. Subarray Sum Closest
Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number.Have you met this question in a real interview? YesExample
2017-11-16 20:54:10 450
原创 LeetCode 138. Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.这个可以有两种方式去做,一个是使用正常的方式,使用map进行
2017-11-16 20:01:45 262
原创 LeetCode 152. Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest
2017-11-15 22:53:22 165
原创 Maximum Subarray Difference
Given an array with integers.Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is the largest.Return the largest difference. NoticeThe subarray should contain at leas
2017-11-15 22:18:54 184
原创 Maximum Subarray IV
Given an integer arrays, find a contiguous subarray which has the largest sum and length should be greater or equal to given length k.Return the largest sum, return 0 if there are fewer than k eleme
2017-11-15 16:18:15 421
原创 Maximum Subarray II
Given an array of integers, find two non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum.NoticeThe subarray should contain a
2017-11-15 14:38:12 242
转载 java泛型解析
作者:fengsehng链接:https://www.nowcoder.com/discuss/62643?type=0&order=0&pos=71&page=0来源:牛客网泛型概述Java泛型(generics)是JDK 5中引入的一个新特性,允许在定义类和接口的时候使用类型参数(type parameter)。声明的类型参数在使用时用具体的类型来替换。优缺点从好的
2017-11-15 09:17:25 438
原创 Word Count (Map Reduce)
Using map reduce to count word frequency.https://hadoop.apache.org/docs/r1.2.1/mapred_tutorial.html#Example%3A+WordCount+v1.0Have you met this question in a real interview? YesEx
2017-11-14 19:00:11 383
转载 hadoop教程---WordCount基础程序分析
分析 WordCount 程序我们先来看看 Hadoop 自带的示例程序 WordCount,这个程序用于统计一批文本文件中单词出现的频率,完整的代码可在下载的 Hadoop 安装包中得到(在 src/examples 目录中)。1.实现Map类见代码清单1。这个类实现 Mapper 接口中的 map 方法,输入参数中的 value 是文本文件中的一行,利用 StringT
2017-11-14 17:09:54 354
原创 Inverted Index
Create an inverted index with given documents.这是一道字符串相关的题目,实际上并不难,其中的一个主要的问题是正则表达式的使用,对于java来说可以直接使用string中的方法split(“\\s+”)作为切分方式,在python需要导入re模块java/** * Definition of Document: * class Docum
2017-11-14 14:48:51 340
原创 LeetCode 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?java/** * Definition for singly-linked list. * public class ListNode { *
2017-11-14 11:03:20 166
原创 LeetCode 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2017-11-14 10:17:41 313
原创 LeetCode 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?对于
2017-11-14 09:38:52 203
原创 LeetCode 147. Insertion Sort List
Sort a linked list using insertion sort.java/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } *
2017-11-13 16:42:24 205
原创 Insert into a Cyclic Sorted List
Given a node from a cyclic linked list which has been sorted, write a function to insert a value into the list such that it remains a cyclic sorted list. The given node can be any single node in the l
2017-11-12 10:42:51 726
原创 Next Permutation II
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
2017-11-11 22:54:35 201
原创 52. N-Queens II
javaclass Solution { int count = 0; public int totalNQueens(int n) { if (n <= 0) { return 0; } dfs(new boolean[n], new boolean[2 * n], new boolean[2 * n],
2017-11-11 18:16:43 167
原创 LeetCode 51. N-Queens
51. N-Queens问题,主要是在使用dfs方法考虑。按照行搜索的方式来对列,主、副对角线来进行查找,分析是否有可以相互攻击的元素javaclass Solution { public List> solveNQueens(int n) { List> result = new ArrayList<>(); if (n <= 0) {
2017-11-11 18:02:18 215
原创 String Permutation
Given two strings, write a method to decide if one is a permutation of the other.Have you met this question in a real interview? Yespythonclass Solution: """ @param: A:
2017-11-11 15:11:12 248
原创 LeetCode 47. 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], [2,1,1
2017-11-10 16:14:30 230
原创 Permutations
Given a list of numbers, return all possible permutations. NoticeYou can assume that there is no duplicate numbers in the list.Have you met this question in a real interview? Y
2017-11-09 23:01:07 233
原创 LeetCode 131. Palindrome Partitioning
直接使用DFS硬怼Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return[ ["aa
2017-11-09 22:41:10 193
原创 216. Combination Sum III
不用多想,直接使用DFS解决Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
2017-11-09 20:27:55 155
原创 Remove Duplicate Numbers in Array
Given an array of integers, remove the duplicate numbers in it. You should:1. Do it in place in the array.2. Move the unique numbers to the front of the array.3. Return the total number of the
2017-11-09 19:23:15 372
原创 LeetCode 90. Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example,If nums = [1
2017-11-09 14:49:14 173
原创 78. Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[
2017-11-09 14:26:59 149
原创 剑指offer---斐波那契数列
大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。这个题目一定要与面试官问清楚,数据最后的输出的个数,使用DP来做非常简单javapublic class Solution { public int Fibonacci(int n) { if (n == 0 || n == 1) { return n;
2017-11-08 22:55:30 202
原创 剑指offer---旋转数组的最小数字
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。如此简单的二分法竟然没有bug free,看来还需要更加努力!javaimport java.util.Arr
2017-11-08 22:43:26 155
原创 剑指offer---两个栈实现队列
用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 javaimport java.util.Stack;public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>(); pub
2017-11-08 22:35:37 150
原创 Connected Component in Undirected Graph
Find the number connected component in the undirected graph. Each node in the graph contains a label and a list of its neighbors. (a connected component (or just component) of an undirected graph is a
2017-11-08 21:20:45 296
原创 Six Degrees
Six degrees of separation is the theory that everyone and everything is six or fewer steps away, by way of introduction, from any other person in the world, so that a chain of "a friend of a friend" s
2017-11-08 19:51:56 237
原创 Remove Substrings
Given a string s and a set of n substrings. You are supposed to remove every instance of those n substrings from s so that s is of the minimum length and output this minimum length. Have you
2017-11-08 14:03:22 205
原创 Word Count (Map Reduce)
Using map reduce to count word frequency.java/** * Definition of OutputCollector: * class OutputCollector { * public void collect(K key, V value); * // Adds a key/value pair to the
2017-11-08 09:09:56 398
原创 Knight Shortest Path
Given a knight in a chessboard (a binary matrix with 0 as empty and 1 as barrier) with a source position, find the shortest path to a destination position, return the length of the route. Return -1 i
2017-11-07 22:45:01 333
原创 Number of Islands
Given a boolean 2D matrix, 0 is represented as the sea, 1 is represented as the island. If two 1 is adjacent, we consider them in the same island. We only consider up/down/left/right adjacent.Find the
2017-11-07 20:00:22 173
原创 Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pai
2017-11-07 14:19:35 139
原创 Topological Sorting
拓扑排序非常重要的一种考题。 topological sort的重点在于如何找到排序的入口java/** * Definition for Directed graph. * class DirectedGraphNode { * int label; * ArrayList<DirectedGraphNode> neighbors; * DirectedGrap
2017-11-06 21:30:46 158
原创 Search Graph Nodes
Given a undirected graph, a node and a target, return the nearest node to given node which value of it is target, return NULL if you can’t find.There is a mapping store the nodes’ values in the given
2017-11-06 20:40:48 546
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人