ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

ÓÃÁ´±íÄ£Äâ´óÕûÊý¼Ó·¨ÔËËã
2014-11-24 02:23:02 ¡¾´ó ÖРС¡¿ ä¯ÀÀ:667´Î
Tags£ºÄ£Äâ ÕûÊý ¼Ó·¨ ÔËËã

ÀýÈ磺9>9>9>NULL + 1>NULL =>
1>0>0>0>NULL
¿Ï¶¨ÊÇʹÓõݹéÀ²£¬²»È»Ã»°ì·¨½â¾ö½øλ+1ÎÊÌ⣬ÒòΪÕâʱºòÒªÈÃÇ°ÃæµÄ½Úµã¼Ó1£¬¶øÎÒÃǵĵ¥Á´±íÊÇÓÀÔ¶Ö¸ÏòÇ°µÄ¡£
´ËÍâ¶ÔÓÚ999+1=1000£¬Ðµõ½µÄÖµµÄλÊý£¨4룩±ÈÔ­À´µÄÁ½¸öÖµ£¨1¸ö1룬1¸ö3룩¶¼¶à£¬ËùÒÔÎÒÃǽ«±íÍ·µÄÖµÉèÖÃΪ0£¬Èç¹û¶à³öһλÀ´£¬¾ÍÔÝʱ´æ·Åµ½±íÍ·¡£µÝ¹é½áÊøºó£¬Èç¹û±íͷΪ1£¬¾ÍÔÚеÄÁ´±íÍâÔÙ¼ÓÒ»¸öеıíÍ·¡£
//head1 length > head2, so M > N
public static int Add(Link head1, Link head2, ref Link newHead, int M, int N)
{
// goto the end
if (head1 == null)
return 0;
int temp = 0;
int result = 0;
newHead = new Link(null, 0);
if (M > N)
{
result = Add(head1.Next, head2, ref newHead.Next, M ¨C 1, N);
temp = head1.Data + result;
newHead.Data = temp % 10;
return temp >= 10
1 : 0;
}
else // M == N
{
result = Add(head1.Next, head2.Next, ref newHead.Next, M ¨C 1, N ¨C 1);
temp = head1.Data + head2.Data + +result;
newHead.Data = temp % 10;
return temp >= 10
1 : 0;
}
}
ÕâÀï¼ÙÉèhead1±Èhead2³¤£¬¶øÇÒM¡¢N·Ö±ðÊÇhead1ºÍhead2µÄ³¤¶È¡£


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
ÉÏһƪ£ºoracleÃæÊÔÌâ¼°Æä´ð°¸ ÏÂһƪ£ºÇ³Ì¸»ªÎªÃæÊÔ¾­Ñé

×îÐÂÎÄÕÂ

ÈÈÃÅÎÄÕÂ

Hot ÎÄÕÂ

Python

C ÓïÑÔ

C++»ù´¡

´óÊý¾Ý»ù´¡

linux±à³Ì»ù´¡

C/C++ÃæÊÔÌâÄ¿