๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“– Problem Solution

[Swift] HackerRank Simple Array Sum

by Fomagran ๐Ÿ’ป 2022. 1. 31.
728x90
๋ฐ˜์‘ํ˜•

 

Problem

 

 

Simple Array Sum | HackerRank

Calculate the sum of integers in an array.

www.hackerrank.com


Source Code

 

let count = Int(readLine()!)!
let nums = String(readLine()!).split(separator: " ").map{Int($0)!}
func simpleArraySum(ar: [Int]) -> Int {
return ar.reduce(0){$0 + $1}
}
print(simpleArraySum(ar: nums))
view raw Simple Array Sum.swift hosted with โค by GitHub
728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€