由买买提看人间百态

topics

全部话题 - 话题: getelement
(共0页)
c*****u
发帖数: 562
1
来自主题: JobHunting版 - 刚刚结束的linkedIn电面
顺着楼上的思路解一题:
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class DeepIteratorImpl2 {
private int cursor;
private List elements;
// Constructor
public DeepIteratorImpl2(Collection> c) {
if (c == null) {
throw new IllegalArgumentException("Invalid input
Collection of Data");
}
this.cursor = 0;
this.elements = new ArrayList(... 阅读全帖
r****i
发帖数: 528
2
来自主题: JobHunting版 - 刚刚结束的linkedIn电面
试着解第一题:
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class DeepIteratorImpl implements Iterator {
//use a flat list to store all elements
private int currIndex;
private ArrayList flatC;
// Constructor
public DeepIteratorImpl (Collection> c) {
currIndex=-1;
flatC=new ArrayList();
getElement(c, flatC);
}

//get all the elements from the collection
private void getElement(C... 阅读全帖
h******3
发帖数: 351
3
来自主题: JobHunting版 - 攒人品, 发面经 (二)
上周四onsite第一轮,今天第二轮.小公司, 真是serious about technology.又是
technical 轮番轰炸,我觉得今天自己有点messy, 下面是记的全的题目.
1. Java Singeton Pattern 以及实现
2. difference between method,class synchronization in Java
3. int getElement(long index, int *pItem)
it is an interface from one array, which might be implemented by other
group. index is between 1 to 1 million. If you input valid index, return 0,
otherwise, return -1
implement following method
long getCount()
Can you call the getElement() as most as 29 times t
y*****e
发帖数: 712
4
L家最爱考的面试题之一就是nested integer了,
还爱考各种iterator的implementation
这题是把两个最爱合在一起了。。。。感觉很有可能出,但网上没找到满意的答案.
题目是这样的
eg: {{1,2},3,{4,{5,6}}}
不断调用iterator的next()返回的序列是 1 2 3 4 5 6
这个data structure的interface是这样的
public interface Data {
// Does this Data hold a collection?
public boolean isCollection();
// Returns the collection contained by this Data, or null if it is a
single element
public Collection> getCollection();
// Returns the single element contained by this Data, or nul... 阅读全帖
j*****s
发帖数: 189
5
来自主题: JobHunting版 - 刚刚结束的linkedIn电面
真的很不爽啊,本来还信心满满的打算好好面,可是我的primary language是c++啊,
非要我写java中的一个collection的东西,还说如果觉得不方便可以用自己习惯的语言
写,可是我连collection有哪些具体的操作都不知道啊。
完了之后三哥说既然不熟就换个问题吧,要实现个blcokingQueue,我不太明白怎么个
blocking法,三哥给我解释,可是三哥的英语我是真的听不懂啊。哎,整的彻底没心情
了。
顺便求助下第一题,有人知道怎么做么?
以下是例子和接口
Example: input: ((1, 3, 5),(4, 7, 3),((2, 3), 4))
1, 3, 5, 4, 7, 3, 2, 3, 4
public class DeepIteratorImpl implements Iterator {
// Constructor
public DeepIteratorImpl (Collection> c) {
// Implementation here
}
public T... 阅读全帖
c*****u
发帖数: 562
6
来自主题: JobHunting版 - 刚刚结束的linkedIn电面
第一题:java.lang.ArrayIndexOutOfBoundsException: -1
T t=flatC.get(currIndex);
用的是楼主提供的testcase
https://dl.dropbox.com/u/7472691/mitbbs/DeepIteratorImplTester.java
也贴个我的第一题吧:
public class DeepIteratorImpl implements Iterator {
private Map> deepIterators;
private Map singleElements;
private int index;
private int maxIndex;
// Constructor
public DeepIteratorImpl(Collection> c) {
if (c... 阅读全帖
x****a
发帖数: 1229
7
DoublyLinkedList class:
public class DoublyLinkedList
{
public E remove (int index) throws IndexOutOfBoundsException
{
if (index<0 || index>= this.size)
throw new IndexOutOfBoundsException();

DLNode cursor = (DLNode)this.head.getSuccessor();

if (index>0)
cursor = this.find(index-1);

DLNode target = (DLNode)cursor.getSuccessor();

(target.getPredecessor()).setSuccessor((DLNode)(tar... 阅读全帖
f*******n
发帖数: 12623
8
来自主题: Java版 - 如何造Array of Generic Type
You can't. T doesn't exist at runtime. It's an illusion. Just remove T and
ask yourself how to do it. If you cannot do it without T, then you cannot do
it with T either:
public class SpecialArray {
Object[] createSpecialArray()
{
return (Object[])Array.newInstance(???, 10);
// How to get T?
// You do not pass anything into this method
}
}
Your problem is that arrays in Java know their component type at runtime. If
you do new String[5], the object knows it's an... 阅读全帖
(共0页)