Skip to content

Instantly share code, notes, and snippets.

View zhuangh's full-sized avatar
🎯
Focusing

Hao Zhuang zhuangh

🎯
Focusing
View GitHub Profile
@zhuangh
zhuangh / rangeModule_smartpointer.cc
Created March 11, 2018 01:43
rangeModule_smartpointer.cc
class STNode{
public:
long l, r, m;
bool tracked;
shared_ptr<STNode> lnode, rnode;
STNode(int ll, int rr):l(ll), r(rr), lnode(nullptr), rnode(nullptr){
m = (l+r)/2;
tracked = false;
}
@zhuangh
zhuangh / rangeModule.cc
Created March 11, 2018 01:33
segTree tree
class STNode{
public:
long l, r, m;
bool tracked;
STNode * lnode, * rnode;
STNode(int ll, int rr):l(ll), r(rr), lnode(nullptr), rnode(nullptr){
m = (l+r)/2;
tracked = false;
}
@zhuangh
zhuangh / wordLadder.cc
Created February 28, 2018 02:21
BFS word ladder problem
class Solution {
public:
int ladderLength(string beginWord, string endWord, vector<string>& wordList) {
queue<string> q;
unordered_set<string> m, dict;
q.push(beginWord);
m.insert(beginWord);
for(const auto & it : wordList)
dict.insert(it);
int level = 1;
### Visualize your network's feature maps here.
### Feel free to use as many code cells as needed.
# image_input: the test image being fed into the network to produce the feature maps
# tf_activation: should be a tf variable name used during your training procedure that represents the calculated state of a specific weight layer
# activation_min/max: can be used to view the activation contrast in more detail, by default matplot sets min and max to the actual min and max values of the output
# plt_num: used to plot out multiple different weight feature map sets on the same block, just extend the plt number for each new feature map entry
def outputFeatureMap(image_input, tf_activation, activation_min=-1, activation_max=-1 ,plt_num=1):
# Here make sure to preprocess your image_input in a way your network expects
# with size, normalization, ect if needed
class Solution {
public:
int largestRectangleArea(vector<int>& heights) {
int space = 0;
int maxh = 0;
int n = heights.size();
stack<int> s;
int i = 0;
int max_space = 0;
while(i<n){
@zhuangh
zhuangh / matrix01DP.cc
Created February 13, 2018 18:58
01 matrix DP
class Solution {
public:
vector<vector<int>> updateMatrix(vector<vector<int>>& matrix) {
int n = matrix.size();
int m = 0;
if( n > 0 ) m = matrix[0].size();
int max_dist = 100000;
vector< vector<int> > dist(n, vector<int> (m, max_dist));
@zhuangh
zhuangh / matrix01.cc
Last active February 13, 2018 18:35
01-matrix
class Solution {
public:
vector<vector<int>> updateMatrix(vector<vector<int>>& matrix) {
int n = matrix.size();
int m = 0;
if(n>0) m = matrix[0].size();
int max_dist = 100000;
queue< pair<int, int> > q;
for(int i = 0; i < n; i++){
@zhuangh
zhuangh / openLock.cc
Created February 12, 2018 01:29
openlock BFS
class Solution {
public:
bool check_deadends(unordered_set<string>& deadends, const string & target){
if(deadends.find(target) != deadends.end()) return true;
deadends.insert(target);
return false;
}
bool check_target(const string & a, const string & b){
return (a==b);
@zhuangh
zhuangh / PredictWinner.cc
Created February 7, 2018 06:46
Advance DP
class Solution {
public:
bool PredictTheWinner(vector<int>& nums) {
int length = nums.size();
std::vector< std::vector<int> > s(length, std::vector<int> (length));
for(int l = 0; l < length; l++){
for(int i=0; i < length - l; i++){
if(l==0) s[i][l] = nums[i];
else if (l==1) s[i][l] = max(nums[i], nums[i+1]);
else if (l==2) s[i][l] = max(nums[i] + min(nums[i+1], nums[i+2]),
@zhuangh
zhuangh / predict_winner.py
Last active February 7, 2018 06:07
advance DP
class Solution:
def PredictTheWinner(self, c):
"""
:type nums: List[int]
:rtype: bool
"""
r = len(c)
t = sum(c)
s = [[0 for i in range(r)] for j in range(r)]
for l in range(r): # l is for the length - 1