Sort by

recency

|

3178 Discussions

|

  • + 0 comments
    public static void plusMinus(List<Integer> arr) {
        int quantityPositive = 0;
        int quantityNegative = 0;
        int quantityZero = 0;
        BigDecimal resultPositive = BigDecimal.valueOf(0);
        BigDecimal resultNegative = BigDecimal.valueOf(0);
        BigDecimal resultZero = BigDecimal.valueOf(0);
    
        for(int i = 0; i < arr.size(); i++ ){
            if(arr.get(i) > 0){
                quantityPositive++;
                resultPositive = BigDecimal.valueOf(quantityPositive).divide(BigDecimal.valueOf(arr.size()), 6, RoundingMode.HALF_UP);
            }else if(arr.get(i) < 0){
                quantityNegative++;
                resultNegative = BigDecimal.valueOf(quantityNegative).divide(BigDecimal.valueOf(arr.size()), 6, RoundingMode.HALF_UP);
            }else{
                quantityZero++;
                resultZero = BigDecimal.valueOf(quantityZero).divide(BigDecimal.valueOf(arr.size()), 6, RoundingMode.HALF_UP);
            }
    
    
        }
    
            System.out.println(resultPositive);
            System.out.println(resultNegative);
            System.out.println(resultZero);
    }
    
  • + 0 comments

    def plusMinus(arr): # Write your code here positive_count = 0 negative_count = 0 zero_count = 0 for num in arr: if num > 0: positive_count += 1 elif num < 0: negative_count += 1 else: zero_count += 1 positive_ratio = positive_count / n negative_ratio = negative_count / n zero_ratio = zero_count / n print(f"{positive_ratio:.6f}") print(f"{negative_ratio:.6f}") print(f"{zero_ratio:.6f}")

  • + 0 comments

    Typescript:

    let result_posative = 0;
    let result_nagative = 0;
    let result_zero = 0;
    for(let i=0;i<arr.length;i++){
       if(arr[i] > 0) {
       result_posative++;
       } else if(arr[i] < 0) {
       result_nagative++;
       } else {
       result_zero++;
       }
    }
    console.log(result_posative / arr.length);
    console.log(result_nagative / arr.length);
    console.log(result_zero / arr.length);
    
  • + 0 comments

    javascript:

    function plusMinus(arr) { let positivo = 0; let negativo = 0; let cero = 0;

    for(let i = 0; i < arr.length; i++){
        if(arr[i] > 0){
            positivo++;
        } else if(arr[i] < 0){
            negativo++;
        } else if(arr[i] == 0){
            cero++;
        }
    }
    
    console.log(positivo / arr.length);
    console.log(negativo / arr.length);
    console.log(cero / arr.length);
    

    }

  • + 0 comments

    Video - Java - Time O(n); Space O(1) https://www.youtube.com/watch?v=YRht_UcDIK4