Redian新闻
>
屌丝眼中的各种大学专业
avatar
屌丝眼中的各种大学专业# Joke - 肚皮舞运动
Q*e
1
抛砖引玉,
struct list_node *
merge2sorted2(struct list_node *a, struct list_node *b)
{
int first_node;
struct list_node *head = NULL;
struct list_node *cur = NULL, *node;
if (a == NULL) return b;
if (b == NULL) return a;
first_node = 1;
while (a || b ) {
if (a && b) {
if (a->data < b->data) {
node = a;
a = a->next;
} else {
node = b;
b = b->next;
}
} else if (a) {
node = a;
a = a->next;
} else {
node = b;
b = b->next;
}
if (first_node) {
head = node;
cur = node;
first_node = 0;
} else {
cur->next = node;
cur = cur->next;
}
}
return head;
}
avatar
l*3
2
想开个公司玩玩,转h4拿ead了就可以开了。如果倒闭了,能转回h1b吗?要重新抽签吗?
avatar
p*g
3
avatar
b*m
4
这个还能多优?

【在 Q*******e 的大作中提到】
: 抛砖引玉,
: struct list_node *
: merge2sorted2(struct list_node *a, struct list_node *b)
: {
: int first_node;
: struct list_node *head = NULL;
: struct list_node *cur = NULL, *node;
: if (a == NULL) return b;
: if (b == NULL) return a;
: first_node = 1;

avatar
w*p
5
Yes you can
You don't need 重新抽签。
avatar
H*7
6
现在大学毕业能找到图中的工作已经很不错了
avatar
c*a
7
差不多
avatar
h*s
8
要在原H1B 797 过期之前吧
avatar
B*u
9
广播电视编导就是播放动物世界?

【在 p*********g 的大作中提到】

avatar
h*n
10
用递归吧,很快就写完了
avatar
p*a
11
如果倒闭了,又有什么关系,继续用h4工作或者继续玩就好了,保证主h1就好了,主h1
保不住了,再想着转h1
avatar
h*n
12
写了三个方法,一个是递归,一个是naive方法,一个是用指向指针的指针来构建
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode* res;

//Method using pointer to pointer
res = P2PMethod(l1,l2);
//res = recursive(l1,l2);
//res = naiveMethod(l1,l2);
return res;
}

ListNode* naiveMethod(ListNode *l1, ListNode *l2)
{
if(l1==NULL&&l2==NULL) return NULL;
if(l1==NULL) return l2;
if(l2==NULL) return l1;
ListNode * curP1 = l1;
ListNode * curP2 = l2;
ListNode newHead(0);
ListNode * cur= &newHead;
while(curP1&&curP2)
{
if(curP1->valval)
{
cur->next = curP1;
curP1 = curP1->next;
}
else
{
cur->next = curP2;
curP2 = curP2->next;
}
cur = cur->next;
}

if(curP1||curP2)
{
while(curP1)
{
cur->next = curP1;
curP1=curP1->next;
cur = cur->next;
}
while(curP2)
{
cur->next = curP2;
curP2=curP2->next;
cur = cur->next;
}
}
cur->next = NULL;


return newHead.next;
}


ListNode* recursive(ListNode *l1, ListNode *l2)
{
if(l1==NULL&&l2==NULL) return NULL;
if(l1==NULL) return l2;
if(l2==NULL) return l1;

if(l1->valval)
{
l1->next = mergeTwoLists(l1->next, l2);
return l1;
}
else
{
l2->next = mergeTwoLists(l1, l2->next);
return l2;
}
}

ListNode* P2PMethod(ListNode *l1, ListNode *l2)
{
ListNode* res;
ListNode** resp = &res;

while(l1||l2)
{
if(l1&&l2)
{
if(l1->val>l2->val)
{
*resp = l2;
resp = &(l2->next);
l2 = l2->next;
}
else
{
*resp = l1;
resp = &(l1->next);
l1 = l1->next;
}
}
else if(l1)
{
*resp = l1;
resp = &(l1->next);
l1 = l1->next;
}
else
{
*resp = l2;
resp = &(l2->next);
l2 = l2->next;
}
}
*resp = NULL;
return res;
}
};
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。