Skip to content

Instantly share code, notes, and snippets.

@mengdiwang
mengdiwang / regex.py
Last active April 25, 2018 05:56
regex.py
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r'<a target="_blank" title="(.*?)" href="(.*?)">(.*?)</a>'
test_str = "<p>  二〇一八年四月二十日<br><br><a target=\"_blank\" title=\"上海证券交易所股票上市规则(2018年4月修订)\" href=\"/aboutus/mediacenter/hotandd/a/20180420/4a6cd527bc7bcac21dd66a2abb60d3d5.doc\">上海证券交易所股票上市规则(2018年4月修订)<br></a><a target=\"_blank\" title=\"《上海证券交易所股票上市规则(2018年4月修订)》修订说明\" href=\"/aboutus/mediacenter/hotandd/a/20180420/f086a86397ee054f984443a8ac9d1f3a.doc\">《上海证券交易所股票上市规则(2018年4月修订)》修订说明</a><br><br type=\"_moz\">&nbsp;</p>"
matches = re.finditer(regex, test_str, re.MULTILINE | re.UNICODE)
$ git rm -r --cached .
$ git add .
$ git commit -m "Clean up ignored files"
# Steps To follow to download your leetcode:
#1. Login to leetcode account on your default browser
#2. Get your session Id for leetcode.com from Browser ( for chrome: press F12, Go to Resources, Go to Cookies and copy value of field 'PHPSESSID'; you can find similar value for firefox and other browsers).
#3. Create a folder to save your leetcode codes.
#4. Keep the downloaded leetcode.py into that folder
#5. Replace PHPSESSID field in leetcode.py file with your session ID (copied in step 2)
#6. run file as 'python leetcode.py
#7. wait for all submssions to download.
# Features:
/*
num[i] > num[j], i < j, find max j-i
example:
[3 4 5 1 3]
i j
*/
#include <vector>
#include <string>
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]
@mengdiwang
mengdiwang / searchInsert.cpp
Created November 1, 2015 05:16
searchInsert
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int lo = 0;
int hi = nums.size()-1;
while(lo<=hi)
{
int mid = ((lo-hi)>>1) + hi;
if(nums[mid] == target)
return mid;
@mengdiwang
mengdiwang / lc_96.cpp
Created October 30, 2015 21:57
Unique Binary Search Trees
class Solution {
public:
int numTrees(int n) {
if(n<=1) return 1;
int *a = new int[n+1];
memset(a, 0, sizeof(int)*(n+1));
a[1] = 1;
a[0] = 1;
for(int i=2; i<=n; i++)
{
@mengdiwang
mengdiwang / lc_116.cpp
Created October 30, 2015 21:12
Populating Next Right Pointers in Each Node
/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
@mengdiwang
mengdiwang / lc_268.cpp
Created October 30, 2015 19:26
Missing Number
class Solution {
public:
int missingNumber(vector<int>& nums) {
int sum = 0;
for(int i=0; i<nums.size(); i++)
{
sum += nums[i];
}
return (1+nums.size())*nums.size()/2 - sum;
}
@mengdiwang
mengdiwang / lc_141.cpp
Created October 30, 2015 19:17
Linked List Cycle
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public: