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
/** | |
* Определяет все ли символы в строке | |
* встречаются по одному разу. | |
* Подходит только для алфавита с количеством | |
* символов не более 32. В данном случае, a-z в нижнем регистре. | |
* | |
* @param {string} str | |
* @returns {boolean} | |
*/ | |
function isUniqueChars(str) { |
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 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
/** | |
* @param {number} dividend | |
* @param {number} divisor | |
* @return {number} | |
*/ | |
var divide = function(dividend, divisor) { | |
if (dividend == INT_MIN && divisor == -1) { | |
return INT_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
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] == "*") { |
NewerOlder