Skip to content

Instantly share code, notes, and snippets.

View OriLiMu's full-sized avatar
😃
热爱生命

Ori OriLiMu

😃
热爱生命
View GitHub Profile
@OriLiMu
OriLiMu / uniqueRemoveDuplicated.cpp
Created February 7, 2025 13:30
uniqueRemoveDuplicated
#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());
@OriLiMu
OriLiMu / subStrReverse.cpp
Created February 7, 2025 13:28
substr,reverse string
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string str = "abcd";
// 使用反向迭代器构造反转字符串
@OriLiMu
OriLiMu / AllSubStringCombination.cpp
Created February 2, 2025 14:48
等长字符串所有组合
#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;
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstddef>
#include <iostream>
#include <vector>
using namespace std;
class Solution {
@OriLiMu
OriLiMu / 541_ReverseStringII.cpp
Created January 31, 2025 04:52
string reverse usage
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstddef>
#include <iostream>
#include <vector>
using namespace std;
class Solution {
@OriLiMu
OriLiMu / 45_JumpGameII.cpp
Created January 29, 2025 07:40
代码可读性中文变量名
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <filesystem>
#include <iostream>
#include <vector>
using namespace std;
@OriLiMu
OriLiMu / getLastOfVec.cpp
Created January 28, 2025 16:41
get last item from vec
#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
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstddef>
#include <iostream>
#include <type_traits>
#include <vector>
using namespace std;
@OriLiMu
OriLiMu / factorial.cpp
Created January 28, 2025 10:50
阶乘factorial
#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) {
@OriLiMu
OriLiMu / mergeTwoLists.cpp
Created January 25, 2025 06:09
mergeTwoSortedList
#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) {}
};