Skip to content

Instantly share code, notes, and snippets.

@jojonki
Last active January 18, 2020 00:47
Show Gist options
  • Save jojonki/6af391d0f9bacde34fb07f4500a2b34a to your computer and use it in GitHub Desktop.
Save jojonki/6af391d0f9bacde34fb07f4500a2b34a to your computer and use it in GitHub Desktop.
python vscode sandbox
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"pythonPath": "${config:python.pythonPath}",
"request": "launch",
"program": "${file}",
"stopOnEntry": false,
"console": "integratedTerminal"
}
]
}i
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def treeNodeToString(root):
if not root:
return "[]"
output = ""
queue = [root]
current = 0
while current != len(queue):
node = queue[current]
current = current + 1
if not node:
output += "null, "
continue
output += str(node.val) + ", "
queue.append(node.left)
queue.append(node.right)
return "[" + output[:-2] + "]"
def stringToTreeNode(input):
input = input.strip()
input = input[1:-1]
if not input:
return None
inputValues = [s.strip() for s in input.split(',')]
root = TreeNode(int(inputValues[0]))
nodeQueue = [root]
front = 0
index = 1
while index < len(inputValues):
node = nodeQueue[front]
front = front + 1
item = inputValues[index]
index = index + 1
if item != "null":
leftNumber = int(item)
node.left = TreeNode(leftNumber)
nodeQueue.append(node.left)
if index >= len(inputValues):
break
item = inputValues[index]
index = index + 1
if item != "null":
rightNumber = int(item)
node.right = TreeNode(rightNumber)
nodeQueue.append(node.right)
return root
{
"python.pythonPath": "/Users/jojonki/anaconda3/envs/py38/bin/python"
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Python",
"args": ["${file}"],
"type": "shell",
"command": "${config:python.pythonPath}",
"problemMatcher": [],
"isShellCommand": true,
"group": {
"kind": "build",
"isDefault": true
},
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment