提交 81f5a35c 编写于 作者: 梦境迷离's avatar 梦境迷离

add rust leetcode

上级 04973ee8
package io.github.dreamylost
/**
*
* @author liguobin@growingio.com
* @version 1.0,2020/3/12
*/
object LeetCode1281 extends App {
def subtractProductAndSum(n: Int): Int = {
val f = n.toString.toCharArray.map(c => Integer.parseInt(c + ""))
f.product - f.sum
}
Console println subtractProductAndSum(234)
}
use std::borrow::BorrowMut;
use std::collections::VecDeque;
use std::ops::Index;
......@@ -7,10 +8,32 @@ pub fn solutions() {
leetcode_1365();
leetcode_1342();
leetcode_1313();
leetcode_1281();
}
struct Solution;
///整数的各位积和之差
fn leetcode_1281() {
println!("leetcode_1281");
impl Solution {
pub fn subtract_product_and_sum(n: i32) -> i32 {
let mut num = n;
let mut muti = 1;
let mut sum = 0;
while num != 0 {
let mut tmp = num % 10;
muti *= tmp;
sum += tmp;
num /= 10;
}
muti - sum
}
}
println!("{}", Solution::subtract_product_and_sum(234));
}
///左旋转字符串
fn interview_58_2() {
println!("interview_58_2");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册