Skip to content

Instantly share code, notes, and snippets.

View icameling's full-sized avatar
🎯
Focusing

icameling

🎯
Focusing
View GitHub Profile
@icameling
icameling / intersection-of-two-arrays.cpp
Created July 18, 2022 12:37
#哈希表 #两个数组的交集
class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
unordered_set<int> same_set;
unordered_set<int> num1_set(nums1.begin(), nums1.end());
for (auto num : nums2) {
if (num1_set.find(num) != num1_set.end())
same_set.insert(num);
}
@icameling
icameling / valid-anagram.cpp
Created July 18, 2022 12:28
#哈希表 #有效的字母异位词
class Solution {
public:
bool isAnagram(string s, string t) {
if (s.size() != t.size()) return false;
int table[26] = {0};
for (int i = 0; i < s.size(); ++i) {
table[s[i] - 'a']++;
table[t[i] - 'a']--;
}
@icameling
icameling / linked-list-cycle-ii.cpp
Created July 18, 2022 11:57
#链表 #环形链表 II
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@icameling
icameling / remove-nth-node-from-end-of-list.cpp
Last active July 18, 2022 11:03
#链表 #删除链表的倒数第N个节点
/**
* Definition for singly-linked list.
* 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) {}
* };
*/
@icameling
icameling / swap-nodes-in-pairs.cpp
Created July 18, 2022 08:47
#链表 #两两交换链表中的节点
/**
* Definition for singly-linked list.
* 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) {}
* };
*/
@icameling
icameling / reverse-linked-list.cpp
Last active July 18, 2022 08:04
#链表 #反转链表
/**
* Definition for singly-linked list.
* 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) {}
* };
*/
@icameling
icameling / design-linked-list.cpp
Last active July 18, 2022 08:04
#链表 #设计链表
class MyLinkedList {
struct Node {
int val;
struct Node* next;
Node(): val(0), next(NULL) {}
Node(int v): val(v), next(NULL) {}
};
Node* head_;
int size_;
@icameling
icameling / remove-linked-list-elements-203.cpp
Last active July 18, 2022 08:04
#链表 #移除链表元素 #leetcode
/**
* Definition for singly-linked list.
* 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) {}
* };
*/
@icameling
icameling / spiral-matrix-ii-59.cpp
Last active July 18, 2022 08:06
#数组 #螺旋矩阵 #leetcode
class Solution {
public:
vector<vector<int>> generateMatrix(int n) {
// 行 列
vector<vector<int>> mat;
for (int i = 0; i < n; ++i) {
vector<int> tmp;
for (int j = 0; j < n; ++j)
tmp.push_back(0);
mat.push_back(tmp);