text stringlengths 1 24.5M |
|---|
/*
* @lc app=leetcode.cn id=394 lang=cpp
*
* [394] å—符串解ç
*/
// @lc code=start
class Solution {
public:
string decodeString(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=395 lang=cpp
*
* [395] 至少有 K 个é‡å¤å—符的最长å串
*/
// @lc code=start
class Solution {
public:
int longestSubstring(string s, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=398 lang=cpp
*
* [398] éšæœºæ•°ç´¢å¼•
*/
// @lc code=start
class Solution {
public:
Solution(vector<int>& nums) {
this->nums = nums;
}
int pick(int target) {
int cnt = 0;
int index = -1;
for (int i = 0; i < nums.size(); i++) {
... |
/*
* @lc app=leetcode.cn id=399 lang=cpp
*
* [399] 除法求值
*/
// @lc code=start
class Solution {
public:
vector<double> calcEquation(vector<vector<string>>& equations, vector<double>& values, vector<vector<string>>& queries) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=4 lang=cpp
*
* [4] 寻找两个æ£åºæ•°ç»„çš„ä¸ä½æ•°
*/
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
// @lc code=start
class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2)
... |
/*
* @lc app=leetcode.cn id=404 lang=cpp
*
* [404] å·¦å¶å之和
*/
// @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:
int ... |
/*
* @lc app=leetcode.cn id=407 lang=cpp
*
* [407] 接雨水 II
*/
// @lc code=start
class Solution {
public:
int trapRainWater(vector<vector<int>>& heightMap) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=413 lang=cpp
*
* [413] ç‰å·®æ•°åˆ—划分
*/
// ç»™ä½ ä¸€ä¸²æ•°å—,返回这串数å—ä¸èƒ½å¤Ÿæž„æˆç‰å·®æ•°åˆ—çš„å串的数目
// @lc code=start
class Solution {
public:
int numberOfArithmeticSlices1(vector<int>& A) {
int count = 0;
int addend = 0;
for ... |
/*
* @lc app=leetcode.cn id=415 lang=cpp
*
* [415] å—符串相åŠ
*/
// @lc code=start
class Solution {
public:
string addStrings(string num1, string num2) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=42 lang=cpp
*
* [42] 接雨水
*/
// @lc code=start
class Solution {
public:
int trap(vector<int>& height) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=421 lang=cpp
*
* [421] 数组ä¸ä¸¤ä¸ªæ•°çš„æœ€å¤§å¼‚或值
*/
// @lc code=start
int dummy = [](){
ios::sync_with_stdio(false);
return 0;
}();
#define maxn 31*2*10000+4
int l[maxn], r[maxn];
int tail;
int ht;
class Solution {
void insert(int num) {
int f = 1 << (ht... |
/*
* @lc app=leetcode.cn id=424 lang=cpp
*
* [424] 替æ¢åŽçš„æœ€é•¿é‡å¤å—符
*/
// @lc code=start
class Solution {
public:
int characterReplacement(string s, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=429 lang=cpp
*
* [429] N 剿 ‘的层åºé历
*/
// @lc code=start
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> children;
Node() {}
Node(int _val) {
val = _val;
}
Node(int _val, vector<Node*> _children) {
val = _val;
... |
/*
* @lc app=leetcode.cn id=43 lang=cpp
*
* [43] å—符串相乘
*/
// @lc code=start
class Solution {
public:
string multiply(string num1, string num2) {
}
};
// @lc code=end
|
/*
// Definition for a Node.
class Node {
public:
int val;
Node* prev;
Node* next;
Node* child;
};
*/
class Solution {
public:
Node* flatten(Node* head) {
//if(head==nullptr) return head;
Node*curr=head;
while(curr){
if(curr->child){
Node*childla... |
/*
* @lc app=leetcode.cn id=434 lang=cpp
*
* [434] å—符串ä¸çš„å•è¯æ•°
*/
// @lc code=start
class Solution {
public:
int countSegments(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=435 lang=cpp
*
* [435] æ— é‡å 区间
*/
// @lc code=start
class Solution {
public:
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
sort(intervals.begin(),intervals.end(),[](vector<int>& l,vector<int>& r){return l[1]<r[1];});
int count=0;
int len=i... |
/*
* @lc app=leetcode.cn id=436 lang=cpp
*
* [436] 寻找å³åŒºé—´
*/
// @lc code=start
class Solution {
public:
int findlocation(vector<pair<int, int>>& arr, int val) {
int n = arr.size();
if (val > arr[n - 1].first) {
return -1;
}
int left = 0;
int right = ... |
/*
* @lc app=leetcode.cn id=437 lang=cpp
*
* [437] 路径总和 III
*/
// @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(n... |
/*
* @lc app=leetcode.cn id=44 lang=cpp
*
* [44] 通é…符匹é…
*/
// @lc code=start
class Solution {
public:
bool isMatch(string s, string p) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=443 lang=cpp
*
* [443] 压缩å—符串
*/
// @lc code=start
class Solution {
public:
int compress(vector<char>& chars) {
}
};
// @lc code=end
|
445. ä¸¤æ•°ç›¸åŠ II
/*
* @lc app=leetcode.cn id=445 lang=cpp
*
* [445] ä¸¤æ•°ç›¸åŠ II
*/
// @lc code=start
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
int stk1[10005],st... |
/*
* @lc app=leetcode.cn id=448 lang=cpp
*
* [448] æ‰¾åˆ°æ‰€æœ‰æ•°ç»„ä¸æ¶ˆå¤±çš„æ•°å—
*/
// @lc code=start
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
int n = nums.size();
for (auto& num : nums) {
int x = (num - 1) % n;
nums[x] += n... |
/*
* @lc app=leetcode.cn id=449 lang=cpp
*
* [449] åºåˆ—化和ååºåˆ—åŒ–äºŒå‰æœç´¢æ ‘
*/
// @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 Codec {... |
/*
* @lc app=leetcode.cn id=450 lang=cpp
*
* [450] åˆ é™¤äºŒå‰æœç´¢æ ‘ä¸çš„节点
*/
// @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=451 lang=cpp
*
* [451] æ ¹æ®å—符出现频率排åº
*/
#include <queue>
#include <map>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
// author dansen
// @lc code=start
class Solution {
public:
struct Node{
char c;
... |
/*
* @lc app=leetcode.cn id=456 lang=cpp
*
* [456] 132模å¼
*/
// @lc code=start
class Solution {
public:
bool find132pattern(vector<int>& nums) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=459 lang=cpp
*
* [459] é‡å¤çš„åå—符串
*/
// @lc code=start
class Solution {
public:
bool repeatedSubstringPattern(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=470 lang=cpp
*
* [470] 用 Rand7() 实现 Rand10()
*/
// @lc code=start
// The rand7() API is already defined for you.
// int rand7();
// @return a random integer in the range 1 to 7
class Solution {
public:
int rand10() {
int row, col, idx;
do {
row = r... |
/*
* @lc app=leetcode.cn id=472 lang=cpp
*
* [472] 连接è¯
*/
// @lc code=start
class Solution {
public:
int son[100000][26];
int cnt[100000];
int idx = 0;
void insert(string s){
int p = 0;
for(int i = 0; i < s.size(); i++){
int u = s[i] - 'a';
if(!son[p][u... |
/*
* @lc app=leetcode.cn id=478 lang=cpp
*
* [478] åœ¨åœ†å†…éšæœºç”Ÿæˆç‚¹
*/
// @lc code=start
class Solution {
public:
double r, x_cen, y_cen;
Solution(double radius, double x_center, double y_center) {
r = radius;
x_cen = x_center;
y_cen = y_center;
}
vector<double> r... |
/*
* @lc app=leetcode.cn id=49 lang=cpp
*
* [49] å—æ¯å¼‚ä½è¯åˆ†ç»„
*/
#include <vector>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
long long coutPairs(vector<int>& nums, int k) {
// å–得最大数å—m
int m = *max_element(nums.begin(), nums.end());
... |
/*
* @lc app=leetcode.cn id=493 lang=cpp
*
* [493] 翻转对
*/
// @lc code=start
class Solution {
public:
int reversePairs(vector<int>& nums) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=496 lang=cpp
*
* [496] ä¸‹ä¸€ä¸ªæ›´å¤§å…ƒç´ I
*/
// @lc code=start
class Solution {
public:
vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
vector<int> v;
for(auto k : nums1){
int s = 0;
int t = -1;
for(au... |
/*
* @lc app=leetcode.cn id=5 lang=cpp
*
* [5] 最长回文å串
*/
// @lc code=start
class Solution {
public:
string longestPalindrome(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=501 lang=cpp
*
* [501] äºŒå‰æœç´¢æ ‘ä¸çš„ä¼—æ•°
*/
// @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 {
publ... |
/*
* @lc app=leetcode.cn id=502 lang=cpp
*
* [502] IPO
*/
// @lc code=start
class Solution {
public:
int findMaximizedCapital(int k, int W, vector<int>& Profits, vector<int>& Capital) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=508 lang=cpp
*
* [508] å‡ºçŽ°æ¬¡æ•°æœ€å¤šçš„åæ ‘å…ƒç´ å’Œ
*/
// @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=509 lang=cpp
*
* [509] æ–æ³¢é‚£å¥‘æ•°
*/
// @lc code=start
class Solution {
public:
int fib(int n) {
int f[n+10];
f[0] = 0;
f[1] = 1;
for(int i=2; i<=n; i++){
f[i] = f[i-1]+f[i-2];
}
return f[n];
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=513 lang=cpp
*
* [513] æ‰¾æ ‘å·¦ä¸‹è§’çš„å€¼
*/
// @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), l... |
/*
* @lc app=leetcode.cn id=520 lang=cpp
*
* [520] æ£€æµ‹å¤§å†™å—æ¯
*/
// @lc code=start
class Solution {
public:
bool detectCapitalUse(string word) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=521 lang=cpp
*
* [521] 最长特殊åºåˆ— â…
*/
// @lc code=start
class Solution {
public:
int findLUSlength(string a, string b) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=53 lang=cpp
*
* [53] 最大ååºå’Œ
*/
// @lc code=start
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int n = nums.size();
int f[n];
f[0] = nums[0];
int m = f[0];
for(int i=1; i<n; i++){
f[i] = nums[i];
... |
/*
* @lc app=leetcode.cn id=530 lang=cpp
*
* [530] äºŒå‰æœç´¢æ ‘的最å°ç»å¯¹å·®
*/
// @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=541 lang=cpp
*
* [541] å转å—符串 II
*/
// @lc code=start
class Solution {
public:
string reverseStr(string s, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=543 lang=cpp
*
* [543] äºŒå‰æ ‘的直径
*/
// @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:
... |
/*
* @lc app=leetcode.cn id=547 lang=cpp
*
* [547] çœä»½æ•°é‡
*/
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
// å¯»æ‰¾æ ‘æ ¹
int Find(vector<int>& root, int index) {
if (root[index] != index) {
... |
/*
* @lc app=leetcode.cn id=551 lang=cpp
*
* [551] å¦ç”Ÿå‡ºå‹¤è®°å½• I
*/
// @lc code=start
class Solution {
public:
bool checkRecord(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=557 lang=cpp
*
* [557] å转å—符串ä¸çš„å•è¯ III
*/
// @lc code=start
class Solution {
public:
string reverseWords(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=56 lang=cpp
*
* [56] åˆå¹¶åŒºé—´
*/
// @lc code=start
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& arr) {
sort(arr.begin(),arr.end());
vector<vector<int>>ans;
int start=arr[0][0];
int end=arr[0][1];
for(int i=1;i<arr... |
/*
* @lc app=leetcode.cn id=563 lang=cpp
*
* [563] äºŒå‰æ ‘çš„å¡åº¦
*/
// @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(n... |
/*
* @lc app=leetcode.cn id=564 lang=cpp
*
* [564] 寻找最近的回文数
*/
// @lc code=start
class Solution {
public:
string nearestPalindromic(string n) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=567 lang=cpp
*
* [567] å—符串的排列
*/
// @lc code=start
class Solution {
public:
bool checkInclusion(string s1, string s2) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=57 lang=cpp
*
* [57] æ’入区间
*/
// @lc code=start
class Solution {
public:
vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
vector<vector<int>> res;
// if (intervals.empty()) {
// res.push_back(newInterval);
... |
/*
* @lc app=leetcode.cn id=572 lang=cpp
*
* [572] å¦ä¸€ä¸ªæ ‘çš„åæ ‘
*/
// @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=576 lang=cpp
*
* [576] 出界的路径数
*/
#include <string>
#include <vector>
using namespace std;
// @lc code=start
class Solution {
public:
int findPaths(int m, int n, int N, int i, int j) {
long long f[N+1][m][n];
memset(f, 0, sizeof(f));
long long MOD=... |
/*
* @lc app=leetcode.cn id=58 lang=cpp
*
* [58] 最åŽä¸€ä¸ªå•è¯çš„长度
*/
// @lc code=start
class Solution {
public:
int lengthOfLastWord(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=587 lang=cpp
*
* [587] å®‰è£…æ …æ
*/
// @lc code=start
class Solution {
public:
vector<vector<int>> outerTrees(vector<vector<int>>& points) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=591 lang=cpp
*
* [591] æ ‡ç¾éªŒè¯å™¨
*/
// @lc code=start
class Solution {
public:
bool isValid(string code) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=6 lang=cpp
*
* [6] Z å—å½¢å˜æ¢
*/
// @lc code=start
class Solution {
public:
string convert(string s, int numRows) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=606 lang=cpp
*
* [606] æ ¹æ®äºŒå‰æ ‘创建å—符串
*/
// @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 {
p... |
/*
* @lc app=leetcode.cn id=61 lang=cpp
*
* [61] 旋转链表
*/
// @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=617 lang=cpp
*
* [617] åˆå¹¶äºŒå‰æ ‘
*/
// @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(null... |
/*
* @lc app=leetcode.cn id=62 lang=cpp
*
* [62] ä¸åŒè·¯å¾„
*/
// @lc code=start
class Solution {
public:
int uniquePaths(int m, int n) {
int f[m][n];
f[0][0] = 1;
for(int i=1; i<m; i++){
f[i][0] = 1;
}
for(int j=1; j<n; j++){
f[0][j] = 1;
... |
/*
* @lc app=leetcode.cn id=621 lang=cpp
*
* [621] 任务调度器
*/
// @lc code=start
class Solution {
public:
int leastInterval(vector<char>& tasks, int n) {
vector<int> Task(26, 0);
int res = 0, restSpace = 0;
for (char t : tasks) {
Task[t - 'A']++;
}
... |
/*
* @lc app=leetcode.cn id=622 lang=cpp
*
* [622] 设计循环队列
*/
#include <queue>
using namespace std;
// @lc code=start
class MyCircularQueue {
public:
queue<int> q;
int cap = 0;
MyCircularQueue(int k) {
cap = k;
}
bool enQueue(int value) {
if(q.size()>=cap){
... |
/*
* @lc app=leetcode.cn id=63 lang=cpp
*
* [63] ä¸åŒè·¯å¾„ II
*/
// @lc code=start
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& g) {
int m = g.size();
int n = g[0].size();
int f[m][n];
f[0][0] = g[0][0]?0:1;
for(int i=1; i<m; i++){
... |
/*
* @lc app=leetcode.cn id=632 lang=cpp
*
* [632] 最å°åŒºé—´
*/
// @lc code=start
/***************************************************
Author: hqztrue
https://github.com/hqztrue/LeetCodeSolutions
Complexity: O(sort(n))
If you find this solution helpful, plz give a star:)
*****************************************... |
/*
* @lc app=leetcode.cn id=636 lang=cpp
*
* [636] å‡½æ•°çš„ç‹¬å æ—¶é—´
*/
// @lc code=start
class Solution {
public:
vector<int> exclusiveTime(int n, vector<string>& logs) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=637 lang=cpp
*
* [637] äºŒå‰æ ‘的层平å‡å€¼
*/
// @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) {}
* };
*/
#include <queue>
using ... |
/*
* @lc app=leetcode.cn id=64 lang=cpp
*
* [64] 最å°è·¯å¾„å’Œ
*/
// @lc code=start
class Solution {
public:
// f[i][j] = max(f[i-1][j], f[i][j-1])
int minPathSum(vector<vector<int>>& g) {
int m = g.size();
int n = g[0].size();
int f[m][n];
f[0][0] = g[0][0];
for(in... |
/*
* @lc app=leetcode.cn id=641 lang=cpp
*
* [641] 设计循环åŒç«¯é˜Ÿåˆ—
*/
// @lc code=start
class MyCircularDeque {
public:
/** Initialize your data structure here. Set the size of the deque to be k. */
MyCircularDeque(int k) {
}
/** Adds an item at the front of Deque. Return true if the ... |
/*
* @lc app=leetcode.cn id=648 lang=cpp
*
* [648] å•è¯æ›¿æ¢
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
class Trie{
private:
Trie * c[26];
bool end=false;
public:
T... |
/*
* @lc app=leetcode.cn id=65 lang=cpp
*
* [65] 有效数å—
*/
// @lc code=start
class Solution {
public:
bool isNumber(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=653 lang=cpp
*
* [653] 两数之和 IV - 输入 BST
*/
// @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) : va... |
/*
* @lc app=leetcode.cn id=655 lang=cpp
*
* [655] è¾“å‡ºäºŒå‰æ ‘
*/
// @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:
vec... |
/*
* @lc app=leetcode.cn id=657 lang=cpp
*
* [657] 机器人能å¦è¿”回原点
*/
// @lc code=start
class Solution {
public:
bool judgeCircle(string moves) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=659 lang=cpp
*
* [659] 分割数组为连ç»ååºåˆ—
*/
// @lc code=start
class Solution {
public:
bool isPossible(vector<int>& nums) {
unordered_map<int, priority_queue<int, vector<int>,greater<int>>> mp;
for (auto& x : nums) {
if (mp.find(x) == mp.end())... |
/*
* @lc app=leetcode.cn id=662 lang=cpp
*
* [662] äºŒå‰æ ‘最大宽度
*/
// @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), le... |
/*
* @lc app=leetcode.cn id=67 lang=cpp
*
* [67] 二进制求和
*/
// @lc code=start
class Solution {
public:
string addBinary(string a, string b) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=671 lang=cpp
*
* [671] äºŒå‰æ ‘ä¸ç¬¬äºŒå°çš„节点
*/
// @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) : va... |
/*
* @lc app=leetcode.cn id=676 lang=cpp
*
* [676] å®žçŽ°ä¸€ä¸ªé”æ³•å—å…¸
*/
// @lc code=start
class MagicDictionary {
public:
/** Initialize your data structure here. */
MagicDictionary() {
}
void buildDict(vector<string> dictionary) {
}
bool search(string searchWord) {
... |
/*
* @lc app=leetcode.cn id=677 lang=cpp
*
* [677] é”®å€¼æ˜ å°„
*/
// @lc code=start
class MapSum {
public:
/** Initialize your data structure here. */
MapSum() {
}
void insert(string key, int val) {
}
int sum(string prefix) {
}
};
/**
* Your MapSum object will be instant... |
/*
* @lc app=leetcode.cn id=68 lang=cpp
*
* [68] 文本左å³å¯¹é½
*/
// @lc code=start
class Solution {
public:
vector<string> fullJustify(vector<string>& words, int maxWidth) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=680 lang=cpp
*
* [680] 验è¯å›žæ–‡å—符串 â…¡
*/
// @lc code=start
class Solution {
public:
bool validPalindrome(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=682 lang=cpp
*
* [682] æ£’çƒæ¯”èµ›
*/
// @lc code=start
class Solution {
public:
int calPoints(vector<string>& ops) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=684 lang=cpp
*
* [684] 冗余连接
*/
// @lc code=start
class Solution {
public:
vector<int> findRedundantConnection(vector<vector<int>>& edges) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=689 lang=cpp
*
* [689] ä¸‰ä¸ªæ— é‡å åæ•°ç»„的最大和
*/
// @lc code=start
class Solution {
public:
vector<int> maxSumOfThreeSubarrays(vector<int>& nums, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=69 lang=cpp
*
* [69] x çš„å¹³æ–¹æ ¹
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
int mySqrt(int x) {
int64_t l = 0, r = x;
int64_t ans = 0;
while... |
/*
* @lc app=leetcode.cn id=692 lang=cpp
*
* [692] å‰K个高频å•è¯
*/
// @lc code=start
class Solution {
public:
vector<string> topKFrequent(vector<string>& words, int k) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=696 lang=cpp
*
* [696] 计数二进制å串
*/
// @lc code=start
class Solution {
public:
int countBinarySubstrings(string s) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=699 lang=cpp
*
* [699] 掉è½çš„æ–¹å—
*/
// @lc code=start
class Solution {
public:
vector<int> fallingSquares(vector<vector<int>>& positions) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=70 lang=cpp
*
* [70] 爬楼梯
*/
// @lc code=start
class Solution {
public:
int climbStairs(int n) {
int f[n+1];
f[0] = 1;
f[1] = 1;
// æ¯æ¬¡éƒ½æœ‰ä¸¤ç§æ–¹å¼çˆ¬æ¥¼æ¢¯
for(int i=2; i<=n; i++){
f[i] = f[i-1]+f[i-2];
}
... |
/*
* @lc app=leetcode.cn id=700 lang=cpp
*
* [700] äºŒå‰æœç´¢æ ‘ä¸çš„æœç´¢
*/
// @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=703 lang=cpp
*
* [703] æ•°æ®æµä¸çš„第 K 大元ç´
*/
#include <vector>
#include <queue>
using namespace std;
// @lc code=start
class KthLargest {
public:
priority_queue<int, vector<int>, greater<int>> q;
int k;
KthLargest(int k, vector<int>& nums) {
this->k = k;
... |
/*
* @lc app=leetcode.cn id=704 lang=cpp
*
* [704] 二分查找
*/
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
// @lc code=start
class Solution {
public:
int search(vector<int>& nums, int t) {
int n = nums.size();
int l=0, r = ... |
/*
* @lc app=leetcode.cn id=707 lang=cpp
*
* [707] 设计链表
*/
// @lc code=start
class MyLinkedList {
public:
/** Initialize your data structure here. */
struct Node{
int val;
Node *next;
Node(int val,Node*ne):val(val),next(ne){}
};
Node *sentry;
int l;
MyLinked... |
/*
* @lc app=leetcode.cn id=71 lang=cpp
*
* [71] 简化路径
*/
// @lc code=start
class Solution {
public:
string simplifyPath(string path) {
}
};
// @lc code=end
|
/*
* @lc app=leetcode.cn id=715 lang=cpp
*
* [715] Range 模å—
*/
// @lc code=start
class RangeModule {
public:
RangeModule() {
}
void addRange(int left, int right) {
}
bool queryRange(int left, int right) {
}
void removeRange(int left, int right) {
}
};
/**
* Y... |
/*
* @lc app=leetcode.cn id=719 lang=cpp
*
* [719] 找出第 k å°çš„è·ç¦»å¯¹
*/
// @lc code=start
class Solution {
public:
int smallestDistancePair(vector<int>& nums, int k) {
}
};
// @lc code=end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.