Skip to content

Instantly share code, notes, and snippets.

View zsh-89's full-sized avatar
🤒
Out sick

zsh zsh-89

🤒
Out sick
View GitHub Profile
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
class TestData
{
#define GET_TWO_OPERANDS { \
y = operands.top(); operands.pop(); \
x = operands.top(); operands.pop(); }
class Solution {
public:
int evalRPN(vector<string> &tokens)
{
stack<int> operands;
class Solution {
public:
void reverseWords(string &s) {
int N = s.size();
string ans(N + 1, '\0');
int state = 0;
bool first_word = true;
int j = 0;
for (int i = N - 1; i >= 0; --i) {
@zsh-89
zsh-89 / gist:14dba930c76c97c79363
Created July 3, 2014 02:00
The one with expected behavior.
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
@zsh-89
zsh-89 / gist:fe3ffef66bad9d9862ba
Created July 3, 2014 01:56
How cv::imshow() breaks _CrtMemDifference()
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
@zsh-89
zsh-89 / gist:931d928e3fcc3d24977e
Created July 3, 2014 01:50
How cv::imread breaks _CrtDumpMemoryLeaks();
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
int main(void)
/**
* Definition for a point.
* struct Point {
* int x;
* int y;
* Point() : x(0), y(0) {}
* Point(int a, int b) : x(a), y(b) {}
* };
*/
bool operator<(const Point &p1, const Point &p2) {
typedef ListNode LNode;
class Solution {
public:
ListNode *insertionSortList(ListNode *head) {
if (!head) return NULL;
LNode *newHead=head; LNode *p=head->next;
newHead->next=NULL;
while (p) {
LNode *cur=p; p=p->next;
newHead=insert(newHead, cur);
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
typedef ListNode LNode;
class Solution {
class Solution {
public:
char *strStr(char *haystack, char *needle) {
if (!haystack || !needle) return NULL;
int N=strlen(needle);
if (N<1) (haystack[0]=='\0') ? haystack : NULL;
int *next=new int[N];
computeNext(needle, next, N);
char *p=haystack; int j=0;