+ 7

Can anybody explain what's bug in my code!!

Everything is good in my code but it's generates some errors with my expected output and i wanted to remove all bugs!! https://code.sololearn.com/czHP8g11jPsZ/?ref=app

7th Dec 2022, 12:32 PM
filibuster
filibuster - avatar
10 Answers
+ 3
Jayakrishna🇮🇳 we need to writing only a function and rest of the work leetcode doing itself. no format required by yourself, you've to return a array only.
7th Dec 2022, 2:04 PM
filibuster
filibuster - avatar
+ 3
SoloProg I was looking for c program, well thanks for c++ codes ☺️
7th Dec 2022, 2:19 PM
filibuster
filibuster - avatar
+ 2
#include<stdio.h> void runningSum(int*ar,int n,int*r){ //void for(int i=1;i<n;i++) *(ar+i)+=ar[i-1]; //r = sizeof(ar)/sizeof(ar[0]); // no need //return ar; // no need as you not saving it.. } int main(){ int ar[] = {3,6,9,8,5}; int n = sizeof(ar)/sizeof(ar[0]); int p; runningSum(ar,n,&p); // arrays are by default pass by reference for(int i=0;i<n;i++) printf("%d ",ar[i]); return 0; }
7th Dec 2022, 1:20 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 can you please solve leetcode 1480 problem.. https://leetcode.com/problems/running-sum-of-1d-array/description/ That's my question the runningSum function should return any address or address block!
7th Dec 2022, 1:36 PM
filibuster
filibuster - avatar
+ 2
So share the code given. To understand problem , Next separately mention your tried function..
7th Dec 2022, 2:08 PM
Jayakrishna 🇮🇳
+ 2
class Solution { public: vector<int> runningSum(vector<int>& nums) { int s=0; for (size_t i=0; i<nums.size(); i++) { s += nums[i]; nums[i] = s; } return nums; } };
7th Dec 2022, 2:16 PM
SoloProg
SoloProg - avatar
+ 2
Jayakrishna🇮🇳 I resolved the problem, you can see my codes attached to my question.
7th Dec 2022, 2:18 PM
filibuster
filibuster - avatar
+ 2
Rajeev Sharma So it asked to use malloc.. Got it. Well done.
7th Dec 2022, 2:28 PM
Jayakrishna 🇮🇳
+ 1
Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. I need to sign up to see problem.. But just looking at description, I think it will give input or manual array data.. Is it asking full code to write? Or just a part of code? How you need to print? Space separated.. Or any other farmat?
7th Dec 2022, 1:53 PM
Jayakrishna 🇮🇳