如何从数字/数字列表中获取整数?
例如,说你有 [5,6] 输出应该是56
我能想到的唯一方法是将每个数字乘以其位置值,然后添加。 像这样的5 x 10 + 6 x 1 = 56
是否有更简单的方法?我想我可以转换为字符串,但是我不想使用字符串。还有其他选择吗?
for example lets say you have
[5,6]
the output should be 56
the only method I can think of is to multiply each digit by its place value and then add it.
like this 5 x 10 + 6 x 1 = 56
Is there a simpler way of doing this? I guess I can convert to string, but I dont want to use string. Any other alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜只是将相应的数字乘以1、10、100等是最简单的。但是您可以以一种很酷的方式进行。
I guess just multiplying corresponding digits by 1, 10, 100 etc. is the simplest. But you can do this in a cool way.