This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Trie { | |
private: | |
struct Node { | |
vector<Node*> children = vector<Node*>(26); | |
bool is_word = false; | |
}; | |
Node* root = new Node; | |
public: | |
/** Initialize your data structure here. */ | |
Trie() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int divide(int dividend, int divisor) { | |
int sign = (dividend < 0) ^ (divisor < 0) ? -1 : 1; | |
long long dvd = dividend; | |
long long dvs = divisor; | |
if (dvd == INT32_MIN && dvs == -1) { | |
return INT32_MAX; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdexcept> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
class Solution { | |
public: | |
bool isValid(string s) { | |
// твой код здесь | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isValid(s) { | |
const brackets = { | |
')': '(', | |
']': '[', | |
'}': '{' | |
}; | |
// в качестве стека в JavaScript можно использовать обычный массив | |
//(если пользоваться только «разрешенными» методами push & pop) | |
const st = []; | |
for (let i = 0; i < s.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int trap(const vector<int>& h) { | |
int n = h.size(); | |
vector<int> left_max(n + 1); | |
vector<int> right_max(n + 1); | |
for (int i = 1; i <= n; i++) { | |
left_max[i] = max(left_max[i - 1], h[i - 1]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int trap(const vector<int>& h) { | |
int n = h.size(); | |
vector<int> left_max(n + 1); | |
vector<int> right_max(n + 1); | |
for (int i = 1; i <= n; i++) { | |
left_max[i] = max(left_max[i - 1], h[i - 1]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Time: O(n * log (n)) | |
// Memory: O(log (n)) | |
/** | |
* @param {number[]} heights | |
* @return {number} | |
*/ | |
var largestRectangleArea = function(heights) { | |
if (!heights.length) { | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} s | |
* @return {boolean} | |
*/ | |
var checkValidString = function(s) { | |
const n = s.length; | |
const dp = new Array(n).fill(0).map(() => new Array(n).fill(false)); | |
for (let i = 0; i < n; i++) { | |
if (s[i] == "*") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LRUCache { | |
typedef pair<int, int> Node; | |
typedef list<Node>::iterator ref; | |
list<Node> q; | |
unordered_map<int, ref> m; | |
int capacity; | |
void insert(int key, int value) { | |
if (m.find(key) != m.end()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
void sortColors(vector<int>& nums) { | |
int p0 = 0; | |
int p1 = 0; | |
int p2 = nums.size() - 1; | |
while (p1 <= p2) { | |
if (nums[p1] == 1) { | |
p1++; |
NewerOlder