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. html系列教程--p param progress rp rt ruby script select small source

    <p> 标签:用户段落划分或折行的标签 <param> 标签:param 元素允许您为插入 XHTML 文档的对象规定 run-time 设置,也就是说,此标签可为包含它的 & ...

  2. ssh框架用JUnit测试

    public class testAuxDict { //读spring配置文件 public static BeanFactory factory = new ClassPathXmlApplica ...

  3. Weblogic 部署注意事项

    Weblogic下部署服务注意事项: 1. 解决weblogic与hibernate的jar包冲突问题: 首 先找到该系统的DOMAIN_HOME(即你所建的域所在的位置)如:域empi的DOMAIN ...

  4. 《C++ Primer Plus 6th》读书笔记 - 第8章 函数探幽

    1. 摘录 默认参数指的是当函数调用中省略了实参时自动使用的一个值. 默认参数并非编程方面的重大突破,而只是提供了一种便捷的方式.使用默认参数,可以减少要定义的析构函数.方法以及方法重载的数量. 试图 ...

  5. Android 多状态按钮 ToggleButton

    ToggleButton      选中状态,未选中状态并且需要为不同的状态设置不同的显示文本.      属性:           checked="true"         ...

  6. [php]php时间戳当中关于时区的问题

    PHP_VERSION = 5.5.11 话说php函数 time() 的起始时间戳是从:GMT 1970-01-01 00:00:00 开始算起的 写了点测试代码: $gmt1 = strtotim ...

  7. 项目关联不上开源项目(library)

    首先是add library的时候重新打开始始终显示关联错误,在reference中出现一个红叉,无论如何都解决不了,remove后重新添加也会有这个问题,Eclipse也没有任何出错提示. 最后在h ...

  8. 看大数据时代下的IT架构(1)业界消息队列对比

    一.MQ(Message Queue) 即 消息队列,一般用于应用系统解耦.消息异步分发,能够提高系统吞吐量.MQ的产品有很多,有开源的,也有闭源,比如ZeroMQ.RabbitMQ. ActiveM ...

  9. 【FZU】2152 文件系统

     Problem 2152 文件系统 Accept: 63    Submit: 126 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  10. 通过crash了解linux页表

    目的: 通过一个c语言实例,了解linux页表的组织结果和mmu的工作原理. 通过页表找到一个物理地址, 对比物理地址与虚拟地址的内容是否一致. 运行环境: $ uname -r3.15.6-200. ...