This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> // 包含 std::unique | |
#include <iostream> | |
#include <vector> | |
int main() { | |
// 初始化向量 | |
std::vector<int> vec = {1, 2, 3, 4, 5, 1}; | |
// 对 vect 进行排序(虽对于 std::unique 不是必需的,但通常来讲最好先排序) | |
std::sort(vec.begin(), vec.end()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() { | |
std::string str = "abcd"; | |
// 使用反向迭代器构造反转字符串 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
vector<string> generateAllPermutations(const vector<string> &strings) { | |
vector<string> result; | |
vector<string> temp = strings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <climits> | |
#include <cmath> | |
#include <cstddef> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <climits> | |
#include <cmath> | |
#include <cstddef> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <climits> | |
#include <cmath> | |
#include <cstddef> | |
#include <cstdio> | |
#include <filesystem> | |
#include <iostream> | |
#include <vector> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
int main() { | |
std::vector<int> vec = {1, 2, 3, 4, 5}; | |
// 获取最后一个元素 | |
int last_element = vec.back(); | |
std::cout << "Last element: " << last_element << std::endl; // 输出 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <climits> | |
#include <cmath> | |
#include <cstddef> | |
#include <iostream> | |
#include <type_traits> | |
#include <vector> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
long long factorial(int n) { | |
if (n == 0 || n == 1) { | |
return 1; | |
} | |
long long result = 1; | |
for (int i = 2; i <= n; ++i) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// nested way | |
struct ListNode { | |
int val; | |
ListNode *next; | |
ListNode() : val(0), next(nullptr) {} | |
ListNode(int x) : val(x), next(nullptr) {} | |
ListNode(int x, ListNode *next) : val(x), next(next) {} | |
}; |
NewerOlder