leetcode/牛客刷题一般核心代码模式,以java为例,保持原class不变情况下,添加输入/输出即可,或者直接将输入变成变量定义.

import java.util.*;

//https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/submissions/
//leetcode
class Solution {
    public int[] constructArr(int[] a) {
        int[] b = new int[a.length];
        int temp = 1;
        for(int ii=0;ii<a.length;ii++){
            b[ii] = temp;
            temp *= a[ii];
        }
        temp = 1;
        for(int ii=a.length-1;ii>=0;ii--){
            b[ii] *= temp;
            temp *= a[ii];
        }
        return b;
    }
}

//enter class->public!
public class ACMdemo {
    public static void main(String[] args) {
        // write your code here
        Solution solution = new Solution();

        Scanner sc=new Scanner(System.in);

        while (sc.hasNext()){
            String templine = sc.nextLine();
            System.out.println(templine);
            if(templine.equals("")){
                continue;
            }
            //
            String[] inputStr = templine.split(",");
//            System.out.println(Arrays.toString(inputStr));
            int[] a = new int[inputStr.length];
            //leetcode enter
            for(int ii=0;ii<a.length;ii++){
                a[ii] = Integer.parseInt(inputStr[ii]);
            }
            int[] b = solution.constructArr(a);
            //
            System.out.println(Arrays.toString(b));
        }

    }
}

相关文章:

  • 2022-02-04
  • 2022-12-23
  • 2021-08-16
  • 2022-01-01
  • 2021-11-09
  • 2021-09-25
  • 2021-12-23
  • 2021-08-17
猜你喜欢
  • 2021-07-19
  • 2021-06-26
  • 2021-09-24
  • 2021-08-14
  • 2021-05-19
  • 2021-04-02
  • 2022-02-21
相关资源
相似解决方案