Given two numbers represented as strings, return multiplication of the numbers as a string.

Note: The numbers can be arbitrarily large and are non-negative.

题意分析:

  本题是求两个用string表示的非负大数的乘积,乘数可以是任意大小。

解答:

  可以用一个临时List表示乘积的每一位,然后对两个乘数每一位两两相乘,并将结果填到相应的List坐标中即可。

AC代码:

class Solution(object):
def multiply(self, num1, num2):
ret_list = [0] * (len(num1) + len(num2))
for i, vi in enumerate(reversed(num1)):
for j, vj in enumerate(reversed(num2)):
ret_list[i + j] += int(vi) * int(vj)
ret_list[i + j + 1] += ret_list[i + j] / 10
ret_list[i + j] %= 10
while len(ret_list) > 1 and ret_list[-1] == 0:
ret_list.pop()
return ''.join(map(str, ret_list[::-1]))

【LeetCode题意分析&解答】43. Multiply Strings的更多相关文章

  1. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  2. 【LeetCode题意分析&解答】37. Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  3. 【LeetCode题意分析&解答】35. Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  4. 【LeetCode题意分析&解答】38. Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  5. 【LeetCode题意分析&解答】42. Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  6. 【LeetCode题意分析&解答】41. First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  7. 【LeetCode题意分析&解答】39. Combination Sum

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  8. 【LeetCode题意分析&解答】36. Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  9. 【LeetCode题意分析&解答】34. Search for a Range

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

随机推荐

  1. HBASE学习笔记--API

    HBaseConfiguration HBaseConfiguration是每一个hbase client都会使用到的对象,它代表的是HBase配置信息.它有两种构造方式: public HBaseC ...

  2. OCP prepare 20140627

    1. catalog start with catalog start with 是一个很好的命令. 有了这个命令后,  基本上可以不再使用catalog数据库了 . 因为可以通过这个命令将以前的备份 ...

  3. $(function() {});和$(document).ready(function() {});区别

    第一个是直接使用Jquery调用function,第二个是在文档加载完毕后才去调用function

  4. ES6第一篇

    //新的数字方面的方法 const I = 3.4893589; console.log(Number.parseInt(I)); console.log(Number.parseFloat(I)); ...

  5. 剑指offer第10题

    import java.util.Scanner; /* 前两种方法是看最低为是不是为1,不为1则向右移动. 第一种只能对正整数有效,对负数不行,因为负数用的是补码,最高外符号位为1,最后右移动,肯定 ...

  6. Beyond Compare设置默认为ANSI格式

    工具 -> 文件格式 -> 选中C,C++,... -> 转换 -> 外部程序(ANSI文件名) 且 编码(选“ANSI”)-> 保存 -> 关闭

  7. php5.3 PHP5.4 PHP5.5 新特性/使用PHP5.5要注意的

      1.PHP 5.3中的新特性 1.1 PHP 5.3中的新特性 1.1.1. 支持命名空间 (Namespace) 毫无疑问,命名空间是PHP5.3所带来的最重要的新特性. 在PHP5.3中,则只 ...

  8. Socket 服务器和客户端通信

    //服务器端package com.svse.service; import java.io.BufferedReader; import java.io.IOException; import ja ...

  9. linux杂记(一)各硬件装置在linux中的代号

    装置 装置在linux内的代号 IDE硬盘机 /dev/hd[a-d] SCSI硬盘机 /dev/sd[a-p] U盘 /dev/sd[a-p](与SCSI硬盘一样) CDROM /dev/cdrom ...

  10. codeforces 13E . Holes 分块

    题目链接 nextt数组表示这个位置的下一个位置. cnt数组表示这个位置 i 到nextt[i]可以弹几次. end[i] 表示在从 i 弹出去的情况下, 最后一个位置是哪里. 然后就看代码吧. # ...