将两个反向存储在链表中的整数求和(即整数的个位存放在了链表首部,一位数对应一个节点),返回的结果仍用链表形式。 给定两个链表ListNode* A,ListNode* B,请返回A+B的结果(ListNode*)。 测试样例: {1,2,3},{3,2,1} 返回:{4,4,4}
加载中...
import java.util.*; /* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Plus { public ListNode plusAB(ListNode a, ListNode b) { // write code here } }
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/ class Plus { public: ListNode* plusAB(ListNode* a, ListNode* b) { // write code here } };
# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Plus: def plusAB(self, a, b): # write code here
/* public class ListNode { public int val; public ListNode next; public ListNode (int x) { val = x; } }*/ class Plus { public ListNode plusAB(ListNode a, ListNode b) { // write code here } }
/* * function ListNode(x){ * this.val = x; * this.next = null; * } */ /** * * @param a ListNode类 * @param b ListNode类 * @return ListNode类 */ function plusAB( a , b ) { // write code here } module.exports = { plusAB : plusAB };
# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Plus: def plusAB(self, a, b): # write code here
package main import . "nc_tools" /* * type ListNode struct{ * Val int * Next *ListNode * } */ /** * * @param a ListNode类 * @param b ListNode类 * @return ListNode类 */ func plusAB( a *ListNode , b *ListNode ) *ListNode { // write code here }
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * * @param a ListNode类 * @param b ListNode类 * @return ListNode类 */ struct ListNode* plusAB(struct ListNode* a, struct ListNode* b ) { // write code here }