This file contains hidden or 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
void LogError(const char *fmt, ...) { | |
va_list vlist; | |
va_start(vlist, fmt); | |
const size_t kLogMessageLength = 128; | |
char log_message[kLogMessageLength]; | |
vsnprintf(log_message, kLogMessageLength, fmt, vlist); | |
LogError(log_message); | |
va_end(vlist); |
This file contains hidden or 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
// https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ | |
class Solution { | |
public: | |
bool isValidSerialization(string preorder) { | |
if (preorder.empty()) | |
return true; | |
int i = preorder.length() - 1; | |
int stack_size = 0; | |
while (i >= 0) { |
This file contains hidden or 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
// https://leetcode.com/problems/increasing-triplet-subsequence/ | |
class Solution { | |
public: | |
bool increasingTriplet(vector<int>& nums) { | |
if (nums.size() < 3) | |
return false; | |
int l = 0, r = nums.size() - 1, u = 0; | |
// increase l as much as possible | |
while (l < nums.size() - 1 && nums[l] >= nums[l + 1]) | |
++l; |
This file contains hidden or 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
/** | |
* https://leetcode.com/problems/largest-bst-subtree/ | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ |
This file contains hidden or 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
<!DOCTYPE html> | |
<head> | |
<style> | |
#container{ | |
border: 1px solid black; | |
margin: 40px auto; | |
width: 200px; | |
} | |
#div1 { |
This file contains hidden or 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
<html><head> | |
</head> | |
<body> | |
<iframe src="http://www.w3schools.com/" name="A"><p> This my first iframe</p></iframe> | |
<iframe src="http://cps.kaist.ac.kr/" name="B"><p> This my second iframe</p></iframe> | |
<iframe src="http://www.example.com/" name="C"><p> This my third iframe</p></iframe> | |
<a href="http://www.kaist.ac.kr" target="B">Change B</a> | |
This file contains hidden or 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 <my_epi/common.h> | |
template <typename T> | |
struct BTNode { | |
T data; | |
shared_ptr<BTNode<T>> left, right; | |
}; | |
typedef BTNode<int> NodeType; |
This file contains hidden or 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
int FindMinTimePeriod(const vector<int>& tasks, int K) { | |
unordered_map<int, int> task_to_last_time; | |
int cur_time = 0; | |
for (int i = 0; i < tasks.size(); ++i) { | |
int cur_task = tasks[i]; | |
auto it = task_to_last_time.find(cur_task); | |
if (it != task_to_last_time.end()) { | |
cur_time = max(cur_time, it->second + K + 1); | |
it->second = cur_time; | |
} else { |
This file contains hidden or 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
struct Meeting { | |
int start, end; | |
}; | |
struct CompareMeeting { | |
bool operator()(const Meeting& a, const Meeting& b) const { | |
if (a.start == b.start) return a.end < b.end; | |
return a.start < b.start; | |
} | |
}; | |
bool IsValidSchedule(vector<Meeting> meetings) { |
This file contains hidden or 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
pair<int, int> FindSubarrayClosestToK(const vector<int>& a, int k) { | |
pair<int, int> range{0, -1}; | |
if (a.empty()) return range; | |
map<int, int> sum_to_idx; | |
int sum = 0; | |
int min_diff = k; | |
sum_to_idx.emplace(0, -1); // S[-1] = 0 so push 0, -1 here! | |
for (int i = 0; i < a.size(); ++i) { |