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 / 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 / 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));
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){
### 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
@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;
@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 / 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;
}
/**
* Definition for an interval.
* struct Interval {
* int start;
* int end;
* Interval() : start(0), end(0) {}
* Interval(int s, int e) : start(s), end(e) {}
* };
*/
#include<string>
#include<iostream>
#include<vector>
using namespace std;
class ShortPalindromes{
public:
string solve(const string & s, int i, int j,
@zhuangh
zhuangh / vec2dIterator.cc
Created April 16, 2018 05:33
2d iterator with remove()
class Vector2D {
private:
vector<vector<int>>::iterator row, iBegin, iEnd;
vector<int>::iterator col;
public:
Vector2D(vector<vector<int>>& vec2d) {
iBegin = row = vec2d.begin();
iEnd = vec2d.end();
if(vec2d.size())
col = row->begin();