Hello everyone,
Just edited it as solved after I added:
1 2 3
|
using namespace std;
using std::vector;
using std::string;
| |
changed to
int i2=0, int3=0, int5=0;
and changed "solution" to "Solution".
Many thanks to all the helps!
--------------------------------
[Below was the original post]
this is my first post, and I have read through the instruction
and FAQ, as well as searching for similar questions here and the Web.
Unfortunately, I have not found an answer to the error message yet.
However, please let me know if I missed anything.
Any idea or feedback is highly appreciated!
My code is as below,
and the error message "type int is unexpected" happened for line 15,
which referred to i2, i3 and i5.
I see no issue though.
I am a newbie in C++,
and I saw other people used "struct solution" and all others the same,
and that worked.
However, I hope to know why this generated error, and how I can make it work.
Thank you very much!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <stdio.h>
#include <vector>
#include <string>
#define NOMINMAX
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
using namespace std;
class solution{
public:
int nthUglyNumber(int n){
vector<int> res(1,1);
int i2 = 0 , int i3 = 0 , int i5 = 0; //initialize to 0
while (res.size() < n){
int m2= res[i2]*2 , m3 = res[i3]*3, m5 = res[i5]*5;
int mn = min(m2, min(m3, m5));
if (mn == m2) ++i2; // check which one is the smallest, sort
if (mn == m3) ++i3;
if (mn == m5) ++i5;
res.push_back(mn);
}
return res.back();
}
};
| |