为什么list的结果是[[A,B][A,B]],而不是[[a,b][A,B]]
请各位高手指点,谢谢
ArrayList list1 = new ArrayList();
ArrayList list = new ArrayList();
list1.add("a");
list1.add("b");
list.add(list1);
第二题:
List* flattenToLL(Node* root) {
List *list1 = (root->left) ? flattenToLL(root->left) : NULL;
List *list2 = (root->right) ? flattenToLL(root->right) : NULL;
root->left=NULL
root->right=list2
// The "middle" list3 cannot be NULL; append list2 to list3
if (!list1) return root; // Nothing to prepend
List *last = list1;
while (last->right) last=last->right; // Go to the end of list1
last->right = root; // Append list3+list2 to the end of list1
return list1... 阅读全帖
I can do it in R, but not sure if sas can also handle it.
I have 26 lists, now I want to generate their pairwise overlaps
I did the overlap in R, now the output is
list1 list2 both_up both_down
a c x x
a b x x
a c x x
.
.
.
b a x x
b b x x
.
.
.
list1 is actually list2, the whole paiwise comparison has 26*26 row
can I transform it to matrix format using proc transpose?
the result should have list1 as ro... 阅读全帖
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: a hash embedded with another hash in R
发信站: BBS 未名空间站 (Fri Apr 11 15:56:40 2014, 美东)
This question is related to my previous question.
I need to design a hash that is embedded with another hash in R in Rstudio
on Win 7.
library(hash)
myf <- function()
{
h1 <- hash()
if (!has.key("first", h1))
{
list1 <- list()
h1.son<- hash()
h1.son["first_son"] <- list1
h1["first"] <- h1.son
}
# second check
if(!has.key("first_son... 阅读全帖
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: a hash embedded with another hash in R
发信站: BBS 未名空间站 (Fri Apr 11 15:56:40 2014, 美东)
This question is related to my previous question.
I need to design a hash that is embedded with another hash in R in Rstudio
on Win 7.
library(hash)
myf <- function()
{
h1 <- hash()
if (!has.key("first", h1))
{
list1 <- list()
h1.son<- hash()
h1.son["first_son"] <- list1
h1["first"] <- h1.son
}
# second check
if(!has.key("first_son... 阅读全帖
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: a hash embedded with another hash in R
发信站: BBS 未名空间站 (Fri Apr 11 15:56:40 2014, 美东)
This question is related to my previous question.
I need to design a hash that is embedded with another hash in R in Rstudio
on Win 7.
library(hash)
myf <- function()
{
h1 <- hash()
if (!has.key("first", h1))
{
list1 <- list()
h1.son<- hash()
h1.son["first_son"] <- list1
h1["first"] <- h1.son
}
# second check
if(!has.key("first_son... 阅读全帖
This question is related to my previous question.
I need to design a hash that is embedded with another hash in R in Rstudio
on Win 7.
library(hash)
myf <- function()
{
h1 <- hash()
if (!has.key("first", h1))
{
list1 <- list()
h1.son<- hash()
h1.son["first_son"] <- list1
h1["first"] <- h1.son
}
# second check
if(!has.key("first_son", h1["first"]))
{
list1 <- list()
h1.son<- hash()
h1.son["first_son"] <- list1
h1["first"] <- h1.son
}
}
myf()
Why in "second check ", h1["first"] st... 阅读全帖
各位大牛,请看看下面这个算法, 这个是不用heap的算法。
我觉得complexity 是 O(k*n), k是list 的个数, n 是list的平均长度。
那是不是这个应该比用heap的更好点啊?
public static ListNode mergeKLists(ArrayList kLists) {
if (kLists==null)
return null;
if (kLists.size()==0)
return null;
// if there is only one list in kLists
if (kLists.size()==1)
return kLists.get(0);
int length = kLists.size();
// initialize the curList with the first item in the list
ListNo... 阅读全帖
Merge List
Given two lists of items (list1 and list2), each list is sorted based on
the
weight in ascending order. Now merge list1 and list2.
return a sorted merged list.
条件:
If one item in list1 has the same id as an item in list2, combine these two
items into one item and the weight is sum of the two previous weights.
Class Item{
int id;
float weight;
}
剩的时间太少, 想了一会没想出来, 感觉应该有个O(n)的解法. 感觉应该是个merge
sort 的变形
请大家指教了, 谢谢
刚店面完,口头答应recommand onsite, 不知最终如何
先聊天,took about 15 minutes.. 然后上题, 先问思路和算法,然后写pcode, read
over the phone
题目大概是这样
social network, billions id, every id has about 100 friends roughly, what is
max connections between any two ppls. write algorithm to return min
connections between two ids: int min_connection(id1, id2)
you can call following functions
expand(id) return friends list of id
expandall(list) return friends union of all the ids in the list
intersection(list1, list2) return intersection
re... 阅读全帖
刚店面完,口头答应recommand onsite, 不知最终如何
先聊天,took about 15 minutes.. 然后上题, 先问思路和算法,然后写pcode, read
over the phone
题目大概是这样
social network, billions id, every id has about 100 friends roughly, what is
max connections between any two ppls. write algorithm to return min
connections between two ids: int min_connection(id1, id2)
you can call following functions
expand(id) return friends list of id
expandall(list) return friends union of all the ids in the list
intersection(list1, list2) return intersection
re... 阅读全帖
Seems you can do O(n^2 log n)
For each pair of numbers, you can get a total of n^2 two-number sums.
Sort them cost O(n^2 log n)
Then you can use your target value T - each sum to get n^2 values sorted.
Then your job is to find whether there are two numbers that sum to any of
those n^2 values. This can be done by merge two sorted lists:
list1: a[i]+a[j] for each 1<=i,j<=n
list2: T-(a[i]+a[j]) for each 1<=i,j<=n
if list1 and list2 have a match, then a[i1]+a[j1] = T-(a[i2]+a[j2]) and that
is the sa... 阅读全帖
Seems you can do O(n^2 log n)
For each pair of numbers, you can get a total of n^2 two-number sums.
Sort them cost O(n^2 log n)
Then you can use your target value T - each sum to get n^2 values sorted.
Then your job is to find whether there are two numbers that sum to any of
those n^2 values. This can be done by merge two sorted lists:
list1: a[i]+a[j] for each 1<=i,j<=n
list2: T-(a[i]+a[j]) for each 1<=i,j<=n
if list1 and list2 have a match, then a[i1]+a[j1] = T-(a[i2]+a[j2]) and that
is the sa... 阅读全帖
2,
cnt=0;
sort all time, see come time tx, keep count(tx)=++cnt
see leave time ty, keep count(ty)=--cnt
for any query time q, find the largest tz<=q, return count(tz)
4,
assume List1 has uniq elements,
create Map by scan list1
then sort on list2 with comparator comparing indice from previous map?
After doing list1.clone() the link between the newly added
element and list1 was broken.
So your 'if' does not hold. If you really understand my
reply, there should have no 'if' in your response.
Many thanks!
So the key is "compiler just looks at the declaration to determine the type"
, and the compiler needs to make sure the element to be added is of the type
surely safe to be added.
So I think that's the same reason why 3 and 4 in the following statements
can't compile:
1 List< ? extends Number> list1 = new ArrayList ();
2 List< ? > list2 = new ArrayList ();
3 list1.add(3.2);
4 list2.add(4.8);
IOException's parent class (the exact type is not known). It's ok to add
F... 阅读全帖
python 问题,急,在线等。要用python写一个function,function 有两个arguments,
这两个arguments是两个lists.该怎么写?
def function(list1, list2) not right,
def function(*list1,*list2) not right,
how to do it?
或是python function只容许有一个list argument?
Thank you so much!