摘要: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. For example: ["2", "1", "+", "3", "*"]... 阅读全文
posted @ 2016-02-19 17:32 小魔仙 阅读(302) 评论(0) 推荐(0) 编辑
摘要: You may have been using Java for a while. Do you think a simple Java array question can be a challenge? Let's use the following problem to test. Problem: Rotate an array of n elements to the right by... 阅读全文
posted @ 2016-02-19 17:17 小魔仙 阅读(368) 评论(0) 推荐(0) 编辑
摘要: If we want to copy an array, we can use either System.arraycopy() or Arrays.copyOf(). In this post, I use a simple example to demonstrate the difference between the two. 1. Simple Code Examples Syst... 阅读全文
posted @ 2016-02-19 17:01 小魔仙 阅读(348) 评论(0) 推荐(0) 编辑
摘要: 注解(也被称为元数据)为我们在代码中添加信息提供了一种形式化的方法,使我们可以在稍后某个时刻非常方便地使用这些数据。 注解的语法比较简单,除了@符号的使用之外,它基本上与Java固有的语法一致。java SE5内置了三种,定义在java.lang中的注解: @Override,表示当前的方法定义将覆盖父类中的方法。 @Deprecated,如果程序员使用了注解它的元素,那么编译器将会发出警告信... 阅读全文
posted @ 2016-02-18 23:35 小魔仙 阅读(1043) 评论(0) 推荐(3) 编辑
摘要: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases... 阅读全文
posted @ 2016-02-17 00:00 小魔仙 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 1. Which statement(s) is (are) correct about thread and process? Select all that apply. (5 points) A. Threads share the same address space of the pare 阅读全文
posted @ 2016-02-16 19:45 小魔仙 阅读(1083) 评论(1) 推荐(0) 编辑
摘要: 题目: 给定一个无序整型数组arr,找到数组中未出现的最小正整数。 例如: arr=[-1,2,3,4]。返回1。 arr=[1,2,3,4]。返回5。 要求时间复杂度为O(N),空间复杂度为O(1)。 解答: 在遍历arr之前先生成两个变量。变量l表示遍历到目前为止,数组arr已经包含的正整数范围是[1,l],所以在没有开始之前l=0,表示arr没有包含任何正整数。变量r表示遍历到目... 阅读全文
posted @ 2016-02-15 01:11 小魔仙 阅读(1707) 评论(0) 推荐(1) 编辑
摘要: 题目: 给定一个整形数组arr,返回排序后的相邻两数的最大差值。 时间复杂度为O(N)。 解答: 如果用排序法实现,其时间复杂度为O(NlogN),而如果利用桶排序的思想(不是桶排序),可以做到O(N),额外空间复杂度为O(N)。遍历arr找到最大值max和最小值min。如果arr的长度为N,准备N+1个桶,把max单独放在第N+1个桶中,[min,max)范围上的数放在1~N号桶里,对于1~N号... 阅读全文
posted @ 2016-02-15 00:08 小魔仙 阅读(4660) 评论(0) 推荐(0) 编辑
摘要: 题目: 用一个整形矩阵matrix表示一个网络,1代表有路,0代表没路,每一个位置只要不越界,都有上下左右4个方向,求从最左上角到最右下角的最短通路值。 例如: 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1 0 0 0 0 1 通路只有1条,由12个1组成,... 阅读全文
posted @ 2016-02-14 23:22 小魔仙 阅读(1205) 评论(0) 推荐(0) 编辑
摘要: 题目一: 给定一个有序数组arr,调整arr使得这个数组的左半部分没有重复部分且升序,而不用保证右部分是否有序。 例如:arr=[1,2,2,2,3,3,4,5,6,6,7,7,8,8,9,9],调整之后arr=[1,2,3,4,5,6,7,8,9…]。 要求: 时间复杂度O(N),额外空间复杂度O(1) 程序:public static void leftUnique(int[] arr) { ... 阅读全文
posted @ 2016-02-14 22:45 小魔仙 阅读(771) 评论(0) 推荐(0) 编辑