由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - array 转换成 linkedlist, 在线等, 挺急的--help is still nee
相关主题
remove a node in O(1) from link list我恨iPhone@Facebook电面
面试面试官错了怎么办?一个Linkedlist面试题的教训
【我自己写的LinkedList为什么总有错?】linklist exercise
amazon onsite 面经问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5
问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,判断linkedlist是否palindrome最优解法是什么?
明天电面,求建议求个java版本的binary tree serialization和deserialization
回馈本版,新鲜店面,新题新气象菜鸟 贴一个 leetcode LRU Cache -- java代码,并求解疑惑。
delete a node in linked list再问大牛们leetcode上面Linkedlist的题,Reverse Nodes in k-G
相关话题的讨论汇总
话题: node话题: head话题: tail话题: int话题: list
进入JobHunting版参与讨论
1 (共1页)
H******e
发帖数: 4682
1
希望static node fromArray(int[] a) {...}中的head或者tail只用到一个, 应该如何
update codes? Expect working codes in visual studio with only head or tail,
which mean eliminate the head or tail. Just 1 variable, no constructor. :)
hint:
You do not need double-linked list. Just think, why do we have head and tail
variables. We do not do anything with head except initial assignment.
class node
{
public int value;
public node next = null;
static node fromArray(int[] a)
{
if (a.Count() == 0) return null;
else
{
node head = new node();
node tail = head;
for (int i = 0; i < a.Count(); i++)
{
tail.value = a[i];
if (i != a.Count() - 1)
{
tail.next = new node();
tail = tail.next;
}
}
return head;
}
}
static void Main(string[] args)
{
int[] c = new int[] { 11, 2, 3 };
node my_list = node.fromArray(c);
while (my_list != null)
{
Console.WriteLine(my_list.value);
my_list = my_list.next;
}
Console.ReadLine();
}
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
再问大牛们leetcode上面Linkedlist的题,Reverse Nodes in k-G问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,
求帮忙看看这个clone graph的解法。弄半天还是不对。 多谢!明天电面,求建议
Populating Next Right Pointers in Each Node II回馈本版,新鲜店面,新题新气象
问到linked list 的题目delete a node in linked list
remove a node in O(1) from link list我恨iPhone@Facebook电面
面试面试官错了怎么办?一个Linkedlist面试题的教训
【我自己写的LinkedList为什么总有错?】linklist exercise
amazon onsite 面经问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5
相关话题的讨论汇总
话题: node话题: head话题: tail话题: int话题: list