text stringlengths 1 24.5M |
|---|
/*
* @lc app=leetcode.cn id=1649 lang=cpp
*
* [1649] é€šè¿‡æŒ‡ä»¤åˆ›å»ºæœ‰åºæ•°ç»„
*/
// @lc code=start
class Solution {
public:
int createSortedArray(vector<int>& instructions) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1669 lang=cpp
*
* [1669] åˆå¹¶ä¸¤ä¸ªé“¾è¡¨
*/
// @lc code=start
/**
* 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, Lis... |
/*
* @lc app=leetcode.cn id=167 lang=cpp
*
* [167] 两数之和 II - è¾“å…¥æœ‰åºæ•°ç»„
*/
// @lc code=start
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1670 lang=cpp
*
* [1670] 设计å‰ä¸åŽé˜Ÿåˆ—
*/
// @lc code=start
class FrontMiddleBackQueue {
public:
FrontMiddleBackQueue() {
}
void pushFront(int val) {
}
void pushMiddle(int val) {
}
void pushBack(int val) {
}
int popFront(... |
/*
* @lc app=leetcode.cn id=1673 lang=cpp
*
* [1673] 找出最具竞争力的ååºåˆ—
*/
// @lc code=start
class Solution {
public:
vector<int> mostCompetitive(vector<int>& nums, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1675 lang=cpp
*
* [1675] 数组的最å°åç§»é‡
*/
// @lc code=start
class Solution {
public:
int minimumDeviation(vector<int>& nums) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1687 lang=cpp
*
* [1687] 从仓库到ç 头è¿è¾“ç®±å
*/
// @lc code=start
class Solution {
public:
int boxDelivering(vector<vector<int>>& boxes, int portsCount, int maxBoxes, int maxWeight) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=17 lang=cpp
*
* [17] 电è¯å·ç çš„å—æ¯ç»„åˆ
*/
// @lc code=start
class Solution {
public:
vector<string> letterCombinations(string digits) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1703 lang=cpp
*
* [1703] å¾—åˆ°è¿žç» K 个 1 çš„æœ€å°‘ç›¸é‚»äº¤æ¢æ¬¡æ•°
*/
// @lc code=start
class Solution {
public:
int minMoves(vector<int>& nums, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1705 lang=cpp
*
* [1705] åƒè‹¹æžœçš„æœ€å¤§æ•°ç›®
*/
// @lc code=start
class Solution {
public:
int eatenApples(vector<int>& apples, vector<int>& days) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1707 lang=cpp
*
* [1707] 与数组ä¸å…ƒç´ 的最大异或值
*/
// @lc code=start
class Trie {
public:
const int L = 30;
Trie* children[2] = {};
int min = INT_MAX;
void insert(int val) {
Trie* node = this;
node->min = std::min(node->min, val);
... |
/*
* @lc app=leetcode.cn id=1719 lang=cpp
*
* [1719] 釿ž„ä¸€æ£µæ ‘çš„æ–¹æ¡ˆæ•°
*/
// @lc code=start
class Solution {
public:
int checkWays(vector<vector<int>>& pairs) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1721 lang=cpp
*
* [1721] 交æ¢é“¾è¡¨ä¸çš„节点
*/
// @lc code=start
/**
* 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 ... |
/*
* @lc app=leetcode.cn id=173 lang=cpp
*
* [173] äºŒå‰æœç´¢æ ‘è¿ä»£å™¨
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), ... |
/*
* @lc app=leetcode.cn id=1745 lang=cpp
*
* [1745] 回文串分割 IV
*/
#include <string>
using namespace std;
// @lc code=start
class Solution {
public:
bool checkPartitioning(string s) {
int n = s.size(), maxl = 0, r = 0, c = 0, len[2 * n + 1], len1[n];
string _s(2 * n + 1, '*');
for (int i = 0;... |
/*
* @lc app=leetcode.cn id=1753 lang=cpp
*
* [1753] 移除石å的最大得分
*/
// @lc code=start
class Solution {
public:
int maximumScore(int a, int b, int c) {
priority_queue<int> q;
int ans = 0;
q.push(a);
q.push(b);
q.push(c);
while(true){
int... |
/*
* @lc app=leetcode.cn id=1760 lang=cpp
*
* [1760] 袋å里最少数目的çƒ
*/
// @lc code=start
class Solution {
public:
int minimumSize(vector<int>& nums, int maxOperations) {
int left = 1, right = *max_element(nums.begin(), nums.end());
int ans = 0;
while (left <= right) {
... |
/*
* @lc app=leetcode.cn id=1766 lang=cpp
*
* [1766] äº’è´¨æ ‘
*/
// @lc code=start
class Solution {
public:
vector<int> getCoprimes(vector<int>& nums, vector<vector<int>>& edges) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1770 lang=cpp
*
* [1770] 执行乘法è¿ç®—的最大分数
*/
// @lc code=start
class Solution {
public:
int maximumScore(vector<int>& nums, vector<int>& mu) {
int n = nums.size();
int m = mu.size();
int f[1010][1010];
f[0][0] = 0;
int res = IN... |
/*
* @lc app=leetcode.cn id=1803 lang=cpp
*
* [1803] 统计异或值在范围内的数对有多少
*/
// @lc code=start
class Solution {
public:
int countPairs(vector<int>& nums, int low, int high) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=1830 lang=cpp
*
* [1830] 使å—符串有åºçš„æœ€å°‘æ“作次数
*/
// @lc code=start
class Solution {
public:
int makeStringSorted(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=19 lang=cpp
*
* [19] åˆ é™¤é“¾è¡¨çš„å€’æ•°ç¬¬ N 个结点
*/
// @lc code=start
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* List... |
/*
* @lc app=leetcode.cn id=1948 lang=cpp
*
* [1948] åˆ é™¤ç³»ç»Ÿä¸çš„é‡å¤æ–‡ä»¶å¤¹
*/
// @lc code=start
class Solution {
public:
vector<vector<string>> deleteDuplicateFolder(vector<vector<string>>& paths) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=198 lang=cpp
*
* [198] 打家劫èˆ
*/
// @lc code=start
class Solution {
public:
int rob(vector<int>& nums) {
int n = nums.size();
if(n == 0){
return 0;
}
if(n == 1){
return nums[0];
}
int f[n+10];
f[0] ... |
/*
* @lc app=leetcode.cn id=199 lang=cpp
*
* [199] äºŒå‰æ ‘çš„å³è§†å›¾
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), lef... |
/*
* @lc app=leetcode.cn id=2 lang=cpp
*
* [2] 两数相åŠ
*/
// @lc code=start
/**
* 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... |
/*
* @lc app=leetcode.cn id=20 lang=cpp
*
* [20] 有效的括å·
*/
// @lc code=start
class Solution {
public:
bool isValid(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=200 lang=cpp
*
* [200] 岛屿数é‡
*/
// @lc code=start
class Solution {
public:
int numIslands(vector<vector<char>>& grid) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=201 lang=cpp
*
* [201] æ•°å—范围按ä½ä¸Ž
*/
// @lc code=start
class Solution {
public:
int rangeBitwiseAnd(int left, int right) {
int i = 1;
if (left == right) {
return left;
}
if (left == 0 ) {
return 0;
}
... |
/*
* @lc app=leetcode.cn id=203 lang=cpp
*
* [203] 移除链表元ç´
*/
// @lc code=start
/**
* 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, List... |
/*
* @lc app=leetcode.cn id=206 lang=cpp
*
* [206] å转链表
*/
// @lc code=start
/**
* 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 *ne... |
/*
* @lc app=leetcode.cn id=208 lang=cpp
*
* [208] 实现 Trie (å‰ç¼€æ ‘)
*/
#include <vector>
#include <map>
#include <string>
using namespace std;
// @lc code=start
class Trie {
public:
Trie* c [26];
char v :1;
/** Initialize your data structure here. */
Trie() {
memset(c, 0, sizeof(c));... |
/*
* @lc app=leetcode.cn id=209 lang=cpp
*
* [209] 长度最å°çš„åæ•°ç»„
*/
// @lc code=start
class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=21 lang=cpp
*
* [21] åˆå¹¶ä¸¤ä¸ªæœ‰åºé“¾è¡¨
*/
// @lc code=start
/**
* 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, Li... |
/*
* @lc app=leetcode.cn id=211 lang=cpp
*
* [211] æ·»åŠ ä¸Žæœç´¢å•è¯ - æ•°æ®ç»“构设计
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <string.h>
using namespace std;
// @lc code=start
struct Node {
bool isword;
Node* children[26];
Node() {
... |
/*
* @lc app=leetcode.cn id=212 lang=cpp
*
* [212] å•è¯æœç´¢ II
*/
// @lc code=start
constexpr int N = 7E3, M = 26;
int n, m, top, tree[N][M], parent[N];
bool isEnd[N], vis[14][14];
char buf[11];
void insert(string str) {
for (char& c : str) c -= 'a';
int rt = 1;
for (int j = str.length() - 1; j >= 0; --j) {
... |
/*
* @lc app=leetcode.cn id=213 lang=cpp
*
* [213] æ‰“å®¶åŠ«èˆ II
*/
// @lc code=start
class Solution {
public:
int rob(vector<int>& nums) {
int n = nums.size();
if(n == 0)return 0;
if(n == 1)return nums[0];
if(n == 2)return max(nums[0], nums[1]);
int f[n+10];
f[... |
/*
* @lc app=leetcode.cn id=214 lang=cpp
*
* [214] 最çŸå›žæ–‡ä¸²
*/
// @lc code=start
class Solution {
public:
string shortestPalindrome(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=215 lang=cpp
*
* [215] 数组ä¸çš„第K个最大元ç´
*/
#include <queue>
using namespace std;
// @lc code=start
class Solution {
public:
int findKthLargest(vector<int>& nums, int k) {
// 用å°å †
priority_queue<int, vector<int>, greater<int>> q;
for(auto v ... |
/*
* @lc app=leetcode.cn id=218 lang=cpp
*
* [218] 天际线问题
*/
// @lc code=start
class Solution {
public:
vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
vector<vector<int>> ans;
priority_queue<pair<int, int>> max_heap;
int i = 0, cur_x = 0, cur_h = 0, len = buil... |
/*
* @lc app=leetcode.cn id=22 lang=cpp
*
* [22] 括å·ç”Ÿæˆ
*/
// @lc code=start
class Solution {
public:
vector<string> generateParenthesis(int n) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=220 lang=cpp
*
* [220] å˜åœ¨é‡å¤å…ƒç´ III
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
bool containsNearbyAlmostDuplicate(vector<int>& n, int k, int t)
{
s... |
/*
* @lc app=leetcode.cn id=222 lang=cpp
*
* [222] å®Œå…¨äºŒå‰æ ‘的节点个数
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : v... |
/*
* @lc app=leetcode.cn id=225 lang=cpp
*
* [225] ç”¨é˜Ÿåˆ—å®žçŽ°æ ˆ
*/
// @lc code=start
class MyStack {
public:
/** Initialize your data structure here. */
MyStack() {
}
/** Push element x onto stack. */
void push(int x) {
}
/** Removes the element on top of the stack and... |
/*
* @lc app=leetcode.cn id=226 lang=cpp
*
* [226] ç¿»è½¬äºŒå‰æ ‘
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nul... |
/*
* @lc app=leetcode.cn id=227 lang=cpp
*
* [227] 基本计算器 II
*/
// @lc code=start
class Solution {
public:
int calculate(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=228 lang=cpp
*
* [228] 汇总区间
*/
// @lc code=start
class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
vector<string> ret;
int i = 0;
int n = nums.size();
while (i < n) {
int low = i;
i++;
... |
/*
* @lc app=leetcode.cn id=23 lang=cpp
*
* [23] åˆå¹¶K个å‡åºé“¾è¡¨
*/
// @lc code=start
/**
* 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, ListN... |
/*
* @lc app=leetcode.cn id=230 lang=cpp
*
* [230] äºŒå‰æœç´¢æ ‘ä¸ç¬¬Kå°çš„å…ƒç´
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) :... |
/*
* @lc app=leetcode.cn id=234 lang=cpp
*
* [234] 回文链表
*/
// @lc code=start
/**
* 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 *... |
/*
* @lc app=leetcode.cn id=235 lang=cpp
*
* [235] äºŒå‰æœç´¢æ ‘的最近公共祖先
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solut... |
/*
* @lc app=leetcode.cn id=236 lang=cpp
*
* [236] äºŒå‰æ ‘的最近公共祖先
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
... |
/*
* @lc app=leetcode.cn id=237 lang=cpp
*
* [237] åˆ é™¤é“¾è¡¨ä¸çš„节点
*/
// @lc code=start
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void deleteNode(ListNode* node... |
/*
* @lc app=leetcode.cn id=239 lang=cpp
*
* [239] æ»‘åŠ¨çª—å£æœ€å¤§å€¼
*/
// @lc code=start
class Solution {
public:
vector<int> maxSlidingWindow(vector<int>& nums, int k)
{
int n = nums.size();
deque<int> q;
vector<int> res;
for (int i = 0; i < n; ++i) {
while ... |
/*
* @lc app=leetcode.cn id=24 lang=cpp
*
* [24] 两两交æ¢é“¾è¡¨ä¸çš„节点
*/
// @lc code=start
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(in... |
/*
* @lc app=leetcode.cn id=240 lang=cpp
*
* [240] æœç´¢äºŒç»´çŸ©é˜µ II
*/
// @lc code=start
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=25 lang=cpp
*
* [25] K 个一组翻转链表
*/
// @lc code=start
/**
* 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, L... |
/*
* @lc app=leetcode.cn id=257 lang=cpp
*
* [257] äºŒå‰æ ‘的所有路径
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x),... |
/*
* @lc app=leetcode.cn id=264 lang=cpp
*
* [264] 丑数 II
*/
// 1, 2, 3, 4, 5, 6, 8, 9, 10, 12
// @lc code=start
class Solution {
public:
int nthUglyNumber(int n) {
if(n == 0) return 0;
int dp[n];
int index2 = 0;
int index3 = 0;
int index5 = 0;
dp[0] = 1;
... |
/*
* @lc app=leetcode.cn id=273 lang=cpp
*
* [273] 整数转æ¢è‹±æ–‡è¡¨ç¤º
*/
// @lc code=start
class Solution {
public:
string numberToWords(int num) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=278 lang=cpp
*
* [278] 第一个错误的版本
*/
// @lc code=start
// The API isBadVersion is defined for you.
// bool isBadVersion(int version);
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
class Solution {
public:
... |
/*
* @lc app=leetcode.cn id=28 lang=cpp
*
* [28] 实现 strStr()
*/
// @lc code=start
class Solution {
public:
int strStr(string haystack, string needle) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=29 lang=cpp
*
* [29] 两数相除
*/
// @lc code=start
class Solution {
public:
int divide(int dividend, int divisor) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=295 lang=cpp
*
* [295] æ•°æ®æµçš„ä¸ä½æ•°
*/
// @lc code=start
class MedianFinder {
public:
/** initialize your data structure here. */
priority_queue<int, vector<int>, greater<int>> small; //å‡åº
priority_queue<int, vector<int>, less<int>> big; //é™åº
MedianFinder()
... |
/*
* @lc app=leetcode.cn id=3 lang=cpp
*
* [3] æ— é‡å¤å—符的最长å串
*/
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_set>
using namespace std;
// @lc code=start
class Solution {
public:
int lengthOfLongestSubstring(stri... |
/*
* @lc app=leetcode.cn id=30 lang=cpp
*
* [30] ä¸²è”æ‰€æœ‰å•è¯çš„å串
*/
// @lc code=start
class Solution {
public:
vector<int> findSubstring(string s, vector<string>& words) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=303 lang=cpp
*
* [303] 区域和检索 - 数组ä¸å¯å˜
*/
#include <vector>
using namespace std;
// @lc code=start
class NumArray {
public:
int f[10010];
NumArray(vector<int>& nums) {
// è®©æ•°ç»„ä¸‹æ ‡ä»Ž1开始,便于处ç†åç§»
f[0] = 0;
for(int i=0; i<... |
/*
* @lc app=leetcode.cn id=304 lang=cpp
*
* [304] 二维区域和检索 - 矩阵ä¸å¯å˜
*/
#include <vector>
using namespace std;
// @lc code=start
class NumMatrix {
public:
// 注æ„ä¸éœ€è¦å¤ªå¤§
int f[1001][1001];
NumMatrix(vector<vector<int>>& matrix) {
// 还是从1开始åšä¸‹æ ‡
in... |
/*
* @lc app=leetcode.cn id=307 lang=cpp
*
* [307] 区域和检索 - 数组å¯ä¿®æ”¹
*/
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
// @lc code=start
class NumArray {
public:
int n;
int *tree;
int lowbit(int x)
{
return x&-x;
}
in... |
/*
* @lc app=leetcode.cn id=307 lang=cpp
*
* [307] 区域和检索 - 数组å¯ä¿®æ”¹
*/
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
// @lc code=start
class NumArray {
public:
struct TreeNode{
int l, r, v;
TreeNode * left = nullptr;
Tr... |
/*
* @lc app=leetcode.cn id=313 lang=cpp
*
* [313] 超级丑数
*/
// @lc code=start
class Solution {
public:
int nthSuperUglyNumber(int n, vector<int>& primes) {
int len = primes.size();
int dp[n];
memset(dp, 0, sizeof(dp));
dp[0] = 1;
int index[len];
memset(ind... |
/*
* @lc app=leetcode.cn id=315 lang=cpp
*
* [315] 计算å³ä¾§å°äºŽå½“å‰å…ƒç´ 的个数
*/
// @lc code=start
class Solution {
public:
vector<int> countSmaller(vector<int>& nums) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=316 lang=cpp
*
* [316] 去除é‡å¤å—æ¯
*/
// @lc code=start
class Solution {
public:
string removeDuplicateLetters(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=32 lang=cpp
*
* [32] 最长有效括å·
*/
// @lc code=start
class Solution {
public:
int longestValidParentheses(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=327 lang=cpp
*
* [327] 区间和的个数
*/
// @lc code=start
class Solution {
public:
struct TreapNode{
int pri;
int key;
TreapNode * son[2];
int size;
int num;
TreapNode(int x){
key = x;
pri = rand();
son[0] = son[1] = NULL;
... |
/*
* @lc app=leetcode.cn id=328 lang=cpp
*
* [328] 奇å¶é“¾è¡¨
*/
// @lc code=start
/**
* 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 *n... |
/*
* @lc app=leetcode.cn id=33 lang=cpp
*
* [33] æœç´¢æ—‹è½¬æŽ’åºæ•°ç»„
*/
// @lc code=start
class Solution {
public:
int search(vector<int>& nums, int target) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=330 lang=cpp
*
* [330] æŒ‰è¦æ±‚è¡¥é½æ•°ç»„
*/
// @lc code=start
class Solution {
public:
int minPatches(vector<int>& nums, int n) {
int patches = 0;
long long x = 1;
int length = nums.size(), index = 0;
while (x <= n) {
if (index < length ... |
/*
* @lc app=leetcode.cn id=336 lang=cpp
*
* [336] 回文对
*/
// @lc code=start
class Solution {
public:
struct node {
int ch[26];
int flag;
node() {
flag = -1;
memset(ch, 0, sizeof(ch));
}
};
vector<node> tree;
void insert(string& s, int ... |
/*
* @lc app=leetcode.cn id=337 lang=cpp
*
* [337] æ‰“å®¶åŠ«èˆ III
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
in... |
/*
* @lc app=leetcode.cn id=34 lang=cpp
*
* [34] åœ¨æŽ’åºæ•°ç»„䏿Ÿ¥æ‰¾å…ƒç´ 的第一个和最åŽä¸€ä¸ªä½ç½®
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
int lower(vector<int>& nums, int t){
... |
/*
* @lc app=leetcode.cn id=341 lang=cpp
*
* [341] æ‰å¹³åŒ–嵌套列表è¿ä»£å™¨
*/
// @lc code=start
/**
* // This is the interface that allows for creating nested lists.
* // You should not implement it, or speculate about its implementation
* class NestedInteger {
* public:
* // Return true if this N... |
/*
* @lc app=leetcode.cn id=344 lang=cpp
*
* [344] å转å—符串
*/
// @lc code=start
class Solution {
public:
void reverseString(vector<char>& s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=347 lang=cpp
*
* [347] å‰ K 个高频元ç´
*/
// @lc code=start
class Solution {
public:
static bool cmp(pair<int, int>& m, pair<int, int>& n) {
return m.second > n.second;
}
vector<int> topKFrequent(vector<int>& nums, int k) {
unordered_map<int, int> occur... |
/*
* @lc app=leetcode.cn id=349 lang=cpp
*
* [349] 两个数组的交集
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
set<i... |
/*
* @lc app=leetcode.cn id=35 lang=cpp
*
* [35] æœç´¢æ’å…¥ä½ç½®
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
int searchInsert2(vector<int>& nums, int t) {
int n = nums.size();
int l... |
/*
* @lc app=leetcode.cn id=350 lang=cpp
*
* [350] 两个数组的交集 II
*/
// @lc code=start
class Solution {
public:
vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=352 lang=cpp
*
* [352] å°†æ•°æ®æµå˜ä¸ºå¤šä¸ªä¸ç›¸äº¤åŒºé—´
*/
#include <queue>
#include <map>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stack>
#include <set>
#include <unordered_set>
#include <string>
using namespace std;
// @lc code=start
typedef long long ... |
/*
* @lc app=leetcode.cn id=355 lang=cpp
*
* [355] 设计推特
*/
// @lc code=start
// Author: Huahua
constexpr size_t kMaxTweets = 10;
class Twitter {
public:
/** Initialize your data structure here. */
Twitter() {}
/** Compose a new tweet. */
void postTweet(int userId, int tweetId) {
auto &tweets =... |
/*
* @lc app=leetcode.cn id=357 lang=cpp
*
* [357] 计算å„ä¸ªä½æ•°ä¸åŒçš„æ•°å—个数
*/
// @lc code=start
class Solution {
public:
int countNumbersWithUniqueDigits(int n) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=367 lang=cpp
*
* [367] 有效的完全平方数
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
bool isPerfectSquare(int num) {
int64_t l=0, r=num;
int64_t ... |
/*
* @lc app=leetcode.cn id=373 lang=cpp
*
* [373] 查找和最å°çš„K对数å—
*/
#include <queue>
#include <map>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
// author dansen
// @lc code=start
class Solution {
public:
struct Node{
int value;
... |
/*
* @lc app=leetcode.cn id=374 lang=cpp
*
* [374] 猜数å—大å°
*/
// @lc code=start
/**
* Forward declaration of guess API.
* @param num your guess
* @return -1 if num is lower than the guess number
* 1 if num is higher than the guess number
* otherwise return 0
* int guess... |
/*
* @lc app=leetcode.cn id=378 lang=cpp
*
* [378] 有åºçŸ©é˜µä¸ç¬¬ K å°çš„å…ƒç´
*/
// @lc code=start
class Solution {
public:
int kthSmallest(vector<vector<int>>& matrix, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=38 lang=cpp
*
* [38] 外观数列
*/
// @lc code=start
class Solution {
public:
string countAndSay(int n) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=382 lang=cpp
*
* [382] é“¾è¡¨éšæœºèŠ‚ç‚¹
*/
// @lc code=start
/**
* 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, ListN... |
/*
* @lc app=leetcode.cn id=383 lang=cpp
*
* [383] 赎金信
*/
// @lc code=start
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=385 lang=cpp
*
* [385] è¿·ä½ è¯æ³•分æžå™¨
*/
// @lc code=start
/**
* // This is the interface that allows for creating nested lists.
* // You should not implement it, or speculate about its implementation
* class NestedInteger {
* public:
* // Constructor initializes an emp... |
/*
* @lc app=leetcode.cn id=387 lang=cpp
*
* [387] å—符串ä¸çš„第一个唯一å—符
*/
// @lc code=start
class Solution {
public:
int firstUniqChar(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=392 lang=cpp
*
* [392] 判æ–ååºåˆ—
*/
// @lc code=start
class Solution {
public:
bool isSubsequence(string s, string t) {
}
};
// @lc code=end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.