Skip to content

Instantly share code, notes, and snippets.

class MyStack {
public:
queue<int> q;
/** Initialize your data structure here. */
MyStack() {
}
/** Push element x onto stack. */
void push(int x) {
class MyQueue {
public:
/** Initialize your data structure here. */
MyQueue() {
}
/** Push element x to the back of queue. */
void push(int x) {
while(!s2.empty()) {
class Solution {
public:
double largestSumOfAverages(vector<int>& A, int K) {
// const int n = A.size();
// vector<vector<double>> dp(K+1, vector<double>(n+1, 0.0));
// vector<double> sum(n+1, 0.0);
// for(int i = 1; i <= n; i++) {
// sum[i] = sum[i-1] + A[i-1];
// dp[1][i] = static_cast<double>(sum[i]) / i;
// }
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char, char> m1;
map<char, char> m2;
bool flag = true;
for(int i = 0; i < s.size(); i++) {
if (m1.find(s[i]) == m1.end() && m2.find(t[i]) == m2.end()) {
m1[s[i]] = t[i];
m2[t[i]] = s[i];
import sys
import time
def spinning_cursor():
while True:
for cursor in '|/-\\':
yield cursor
spinner = spinning_cursor()
for _ in range(50):
class Solution {
public:
vector<int> partitionLabels(string S) {
vector<int> last_indx(128, 0);
for(int i = 0; i < S.size(); i++)
last_indx[S[i]] = i;
vector<int> ans;
int start = 0;
int end = 0;
for(int i = 0; i < S.size(); i++) {
/**
* 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 {
class Solution {
public:
string convertToTitle(int n) {
string result;
int remain = 0;
while(n > 0) {
remain = (--n) % 26;
result.push_back(remain + 65);
n /= 26;
}
class Solution {
public:
Solution() {
for(string::size_type i = 0; i < chars.size(); i++) {
charToValueMap[chars[i]] = i;
}
}
// Encodes a URL to a shortened URL.
string encode(string longUrl) {
class Solution {
public:
int countPrimes(int n) {
if (n == 1 || n == 0) return 0;
vector<bool> passed(n, true);
passed[0] = false, passed[1] = false;
for(int i = 0; i < sqrt(n); i++) {
if (passed[i]) {
for(int j = i * i; j < n; j += i) {
passed[j] = false;