or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
Leetcode刷題學習筆記–Set/Multiset
Introduction
ref : Difference Between set, multiset, unordered_set, unordered_multiset in C++
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →當成hash table使用
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Time Complexity
ref : Data Structures: MULTI_SET vs SET vs UNORDERED_SET
Code snippet
檢查資料是否重複
把每筆資料轉換成單一的識別碼,從而檢查是否重複。可以使用set。
只能insert和erase不能修改資料
因為multiset和unordered_multiset可以允許重複的資料,
使用erase或刪除相同的資料,所以必須使用find。
如果是插入到set或是multiset,可以知道插入的位置。
視情況如果想知道insert的位置。
Traversal the set
使用iterator來存取所有的item,或是使用for loop來存取所有的資料。
ref : Different ways to iterate over a set in C++
改變Set排列順序
Sets of pairs in C++
ref : Sets of pairs in C++
在Set中存放pairs。則會先依pairs first element排序,如果first element一樣就會用second element排序。
Custom Comparator
ref : Using custom std::set comparator
36. Valid Sudoku(Medium)
找出行,列,每個block是否有數字重複。
929. Unique Email Addresses(Easy)
找出不同的email address,判斷規則參考題目。
完整程式碼如下:
220. Contains Duplicate III
給你一個vector<int> nums, 找出index差小於等於k,且數字差小於等於t。
\(abs(num[i] - nums[j]) <= t\) 且 \(abs(i - j) <= k\)。
tags:
leetcode
刷題