Wrong Output issue leetcode (HELP)//added more tags
Opened this issue · 0 comments
varuogm commented
question link
This works
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
//this works
vector <int > v;
int cnt=0;
for(int i=0;i<nums.size();i++)
{
for(int j=0;j<nums.size();j++)
{
if(nums[i]>nums[j])
cnt++;
}
v.push_back(cnt);
cnt=0;
}
return v;
}
};
BUT NOT THIS despite having same method on test case
Your input
[8,1,2,2,3]
Output
[4,0,1,2,3]
Expected
[4,0,1,1,3]
class Solution {
public:
vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
vector <int > v;
int cnt;
for(int i=0;i<nums.size();i++)
{
for(int j=0;j<nums.size();j++)
{
if(nums[i]>nums[j])
cnt++;
}
nums[i]=cnt;
cnt=0;
}
return nums;
}
};