Add Two Numbers
来源:互联网 发布:逍遥西游源码 编辑:程序博客网 时间:2024/05/15 12:10
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { // Start typing your C/C++ solution below // DO NOT write int main() function int k=0,choice=1; ListNode *L1=l1,*L2=l2,*pre1,*pre2; while(l1!=NULL||l2!=NULL){ if(l1!=NULL&&l1->next==NULL){ pre1=l1; } if(l2!=NULL&&l2->next==NULL){ pre2=l2; } if(l1==NULL){ k=k+l2->val; l2->val=k%10; choice=2; l2=l2->next; }else if(l2==NULL){ k=k+l1->val; l1->val=k%10; choice=1; l1=l1->next; }else { k=l1->val+l2->val+k; l1->val=l2->val=k%10; l1=l1->next; l2=l2->next; } if(k>=10){ k=1; }else k=0; } if(choice==1){ if(k==1){ ListNode *node = new ListNode(1); pre1->next = node; } return L1; }else{ if(k==1){ ListNode *node = new ListNode(1); pre2->next = node; } return L2; } }};
- Add two numbers & Add binary
- LeetCode: Add Two Numbers
- Add Two Numbers
- LeetCode: Add Two Numbers
- [LeetCode]Add Two Numbers
- LeetCode Add Two Numbers
- Leetcode: Add Two Numbers
- Add Two Numbers
- LeetCode : Add Two Numbers
- LeetCode Add Two Numbers
- [LeetCode] Add Two Numbers
- LeetCode4: Add Two Numbers
- Leetcode : Add Two Numbers
- Add Two Numbers
- 【leetcode】Add Two Numbers
- add two numbers
- Add Two Numbers
- Add Two Numbers
- 使用C#开发ActiveX控件
- 获取spring bean 容器中实例,非创建新实例
- xcode project
- C语言中的volatile
- ESB 案例解析和项目实施经验分享,第 3 部分: ESB 项目需求分析和方案设计浅谈
- Add Two Numbers
- build setting
- Scaling Distributed Counters
- Dwr的简单使用, 非Spring 管理。
- xcode Workspaces
- Android Activity 生命周期
- Myeclipse 快捷键
- <iOS, Android>移动原型工具总结
- CH BR4思考熊(恒等有理式-逆波兰表达式求值)