-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlusMinus.swift
More file actions
24 lines (20 loc) · 767 Bytes
/
PlusMinus.swift
File metadata and controls
24 lines (20 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// https://www.hackerrank.com/challenges/plus-minus/problem
import Foundation
// Complete the plusMinus function below.
func plusMinus(arr: [Int]) -> Void {
var positiveCount: Int = 0
var negativeCount: Int = 0
var zeroCount: Int = 0
if arr.count < 0 && arr.count >= 100 {
print("invalid")
}
for i in arr {
if i <= -100 && i >= 100 { print("invalid") }
if i == 0 { zeroCount += 1 }
else if i > 0 { positiveCount += 1 }
else if i < 0 { negativeCount += 1 }
}
print(String(format: "%.6f", Double(positiveCount) / Double(arr.count)))
print(String(format: "%.6f", Double(negativeCount) / Double(arr.count)))
print(String(format: "%.6f", Double(zeroCount) / Double(arr.count)))
}