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
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. | |
For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0]. | |
Note: | |
You must do this in-place without making a copy of the array. | |
Minimize the total number of operations. | |
Credits: | |
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases. |
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
""" | |
ATTENTION: | |
When using executemany with a list of tuples, the numbers representing the rows has to be strictly from 1 to the last. Or else it won't work. | |
I really don't understand why. | |
""" | |
import cx_Oracle | |
from parserFWF import getConfigDF | |
HOTEL_CONFIG = getConfigDF() #dataframe |
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Nov 4 22:04:24 2015 | |
@author: yiling | |
This is done by change the graph g. There must be other ways to better the script | |
""" | |
import random |
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
--求一列中第二大的数据 | |
select max(PersonId) from Address where PersonID not in (select MAX(PersonId) FROM Address) | |
--Use < is faster than not in | |
SELECT max(Salary) | |
FROM Employee | |
WHERE Salary < | |
(SELECT max(Salary) | |
FROM Employee); |
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
Comment | |
https://leetcode.com/problems/bulls-and-cows/ | |
First my solution is to loop it for once to get the dict of the secret. Then loop it for a second time. | |
Then I see that it can be done in one loop. |
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
# | |
# Definition for a binary tree node. | |
# class TreeNode(object): | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution(object): | |
def invertTree(self, root): |
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(object): | |
def gameOfLife(self, board): | |
""" | |
:type board: List[List[int]] | |
:rtype: void Do not return anything, modify board in-place instead. | |
""" | |
def Nnearby(i,j): | |
n = 0 | |
if j >= 1 and board[i][j-1]==1: n+=1 | |
if j+1 < len(board[0]) and board[i][j+1]==1: n+=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(object): | |
def gameOfLife(self, board): | |
""" | |
:type board: List[List[int]] | |
:rtype: void Do not return anything, modify board in-place instead. | |
""" | |
def Nnearby(i,j): | |
n = 0 | |
if j >= 1 and board[i][j-1]==1: n+=1 | |
if j+1 < len(board[0]) and board[i][j+1]==1: n+=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: | |
void inorderTraversalHelper(TreeNode* root, vector<int>& x) { | |
if (!root) return; | |
if (root->left) inorderTraversalHelper(root->left,x); | |
x.push_back(root->val); | |
if (root->right) inorderTraversalHelper(root->right,x); | |
} | |
vector<int> inorderTraversal(TreeNode* root){ | |
vector<int> x; |
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
/*My naive solution...only beats 0.6% of people... | |
因为..因为有好多numTrees(n)都重复算了... | |
所以把这个改成DP的话应该就可以加快不少时间 | |
*/ | |
class Solution { | |
public: | |
int numTrees(int n) { | |
int r = 0; | |
if (n==0) return 0; |
OlderNewer