Simple Array Sum

Sort by

recency

|

3486 Discussions

|

  • + 0 comments

    So what???

  • + 0 comments
    int simpleArraySum(vector<int> ar) {
        int sum=0;
        int n = ar.size();
        for(int i=0; i<n; i++){
            sum += ar[i];
        }
        return sum;
    }
    
  • + 0 comments
    class Result {
        public static int simpleArraySum(List<Integer> ar) {
            return ar.stream().mapToInt(Integer::intValue).sum();
        }
    }
    
  • + 0 comments

    import java.util.*; public class Solution{ public static void main(String[] args) { int sum=0; Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i

  • + 0 comments

    A solution that I liked more (Python 3).

    def simpleArraySum(ar):
        # Write your code here
        return reduce(lambda x, y: x+y, ar)
    

    Note: First, you need to import the necessary file:

    from functools import reduce