LeetCodeテクニック(C++)
2681 ワード
/*****************************************************************************/
/**** STRING: ****/
/*****************************************************************************/
int i = atoi(cstr); //const char* => int
int i = stoi(str); //string => int
int l = stol(str); //string => long
string str = to_string(i); //int、long => string
strcpy(cstr, str.c_str()); //string => char*。 strcpy ,
str.find('a') != str.npos //
str.substr(index, length); //length + index > str.length() length ,
str.replace(index, length, "string"); // "string" index length
std::reverse(str.begin(), str.end()); //
/*****************************************************************************/
/**** VECTOR: ****/
/*****************************************************************************/
auto i = vect.begin();
auto i = vect.end();
auto i = vect.rbegin();
auto i = vect.rend();
int i = vect.size();
vect.push_back();
vect.pop_back();
vect.empty();
auto maxElementIterator = max_element(vect.begin(), vect.end());
auto minElementIterator = min_element(vect.begin(), vect.end());
erase() ,
/*****************************************************************************/
/***** MAP: ****/
/*****************************************************************************/
intStrMap.push_back(pair (1, str)); //
int tmpFirst = elementIterator->first; //
string tmpSecond = elementIterator->second; //
/*****************************************************************************/
/***** SET: ****/
/*****************************************************************************/
set_intersection //
set_union //
set_difference //
set_symeetric_difference //
A.empty();
set_union(A.begin, A.end(), B.begin(), B.end(), inserter(C, C.begin())); //A、B C
/*****************************************************************************/
/***** LIST: , , , ****/
/*****************************************************************************/
numList.empty();
numList.front(); //
numList.back(); //
numList.push_front(); //
numList.pop_front(); //
numList.push_back(); //
numList.pop_back(); //
numList.sort(); //
numList.size(); //
numList.reverse(); // ,
numList.unique(); // ,
numList.swap(anotherList); // ,