刷题专用Gist
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
let inputCGImage = UIImage(contentsOfFile: "<filename>")!.CGImage | |
let width = CGImageGetWidth(inputCGImage) | |
let height = CGImageGetHeight(inputCGImage) | |
let bytesPerPixel = 4 | |
let bytesPerRow = bytesPerPixel * width | |
let bitsPerComponent = 8 | |
let pixels = UnsafeMutablePointer<UInt32>(calloc(height * width, sizeof(UInt32))) | |
let colorSpace = CGColorSpaceCreateDeviceRGB() |
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
## Refer to http://caffe.berkeleyvision.org/installation.html | |
# Contributions simplifying and improving our build system are welcome! | |
# cuDNN acceleration switch (uncomment to build with cuDNN). | |
USE_CUDNN := 1 | |
# CPU-only switch (uncomment to build without GPU support). | |
# CPU_ONLY := 1 | |
# uncomment to disable IO dependencies and corresponding data layers |
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
r.db('ErrorTracker').table('logs').group('message').map(function(doc){ | |
return { | |
count: 1, | |
from: doc('timestamp'), | |
to: doc('timestamp'), | |
browsers: r([doc('ua')('family')]) | |
} | |
}).reduce(function(left, right){ | |
return { | |
count: left('count').add(right('count')), |
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 { | |
private: | |
void spiral_r(vector<vector<int> > const& matrix, | |
vector<int> &result, | |
int m, int n, int start_m, int start_n) { | |
if (m<=0 || n<=0) return; | |
if (n == 1) { | |
for (int i = 0; i < m; i++) result.push_back(matrix[start_m+i][start_n]); | |
return; | |
} else if (m == 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 threeSumClosest(vector<int> &num, int target) { | |
sort(num.begin(), num.end()); | |
int result = 0, difference = INT_MAX; | |
for (size_t i = 0; i < num.size() - 2; i++) { | |
size_t begin = i + 1, end = num.size() - 1; | |
while (begin < end) { | |
int tmp_res = num[i] + num[begin] + num[end]; | |
int tmp_diff = tmp_res - target; |
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: | |
vector<vector<int> > threeSum(vector<int> &num) { | |
sort(num.begin(), num.end()); | |
vector<vector<int> > result; | |
unordered_map<int, vector<vector<size_t> > > lookup; | |
int prev_i = 0; // avoid duplication | |
for (size_t i = 0; i < num.size(); i++) { | |
if (i > 0 && num[i] == prev_i) continue; | |
prev_i = num[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 Solution { | |
public: | |
void merge(int A[], int m, int B[], int n) { | |
int C[m+n]; | |
int a = 0, b = 0, c = 0; | |
while (a < m && b < n) { | |
while (a < m && A[a] <= B[b]) { | |
C[c++] = A[a++]; | |
} | |
while (b < n && B[b] <= A[a]) { |
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: | |
vector<int> getRow(int rowIndex) { | |
if (rowIndex < 0) return vector<int>(); | |
vector<int> result{1}; | |
while (rowIndex-- > 0) { | |
vector<int> tmp{1}; | |
for (auto start = result.begin() + 1; start != result.end(); start++) { | |
tmp.push_back(*(start-1) + *start); | |
} |
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
//C++11 | |
class Solution { | |
public: | |
vector<vector<int> > generate(int numRows) { | |
if (numRows <= 0) return vector<vector<int> >(); | |
vector<vector<int> > result; | |
result.push_back(vector<int>{1}); | |
if (numRows == 1) return result; | |
result.push_back(vector<int>{1, 1}); | |
if (numRows == 2) return result; |
NewerOlder