intremoveDuplicates(vector<int>& nums){ int res = nums.size(); if (res == 0) return0; int temp = nums[0]; auto it = nums.begin() + 1; while (it != nums.end()) { int d = *it; if (d == temp) { nums.erase(it); res--; continue; } temp = d; it++; } return res; }
intremoveDuplicates(vector<int>& nums){ int res = nums.size(); if (res == 0) return0; auto it1 = nums.begin(); auto it2 = nums.begin() + 1; while (it2 != nums.end()) { int d = *it1; int t = *it2; while (t == d) { it2++; res--; if (it2 != nums.end()) t = *it2; else return res; } it1++; it2++; *it1 = t; } return res; }
If the type is int (the default), you might write this in yylex:
1 2 3 4
… yylval = value; /* Put value onto Bison stack. */ return INT; /* Return the type of the token. */ …
When you are using multiple data types, yylval’s type is a union made from the %union declaration (see The Union Declaration). So when you store a token’s value, you must use the proper member of the union. If the %union declaration looks like this:
1 2 3 4 5
%union { int intval; double val; symrec *tptr; }
then the code in yylex might look like this:
1 2 3 4
… yylval.intval = value; /* Put value onto Bison stack. */ return INT; /* Return the type of the token. */ …
enum枚举类型
1
enum 枚举名 {枚举元素1,枚举元素2,……};
第一个枚举成员的默认值为整型的 0,后续枚举成员的值在前一个成员上加 1,可以在定义枚举类型时改变枚举元素的值。在C 语言中,枚举类型是被当做 int 或者 unsigned int 类型来处理的。