Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
coding

Selim Ozturk selimslab

:octocat:
coding
View GitHub Profile
View regex.py
import re
def remove_digits(word):
return re.sub("\d+", "", word)
def find_n_digits_only(n, word):
return re.findall(r"\d" + "{" + str(n) + "}", word)
View csv.py
import csv
def read_csv(file_path):
with open(file_path, "r") as csvFile:
# or reader = csv.DictReader(csvFile)
reader = csv.reader(csvFile)
for row in reader:
yield row
View dijkstra.py
from collections import defaultdict
class Graph:
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
View graphSearch.go
package main
import (
"fmt"
)
func bfs(graph map[string][]string, name string) []string {
var searchQueue []string
searchQueue = append(searchQueue, graph[name]...)
View bfs.py
from collections import deque
def bfs(graph, start_node):
queue = deque()
queue.append(start_node)
visited = list()
while queue:
node = queue.popleft()
if node not in visited:
View checkBST.py
""" Node is defined as
class node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
"""
def checkBST(root, min=0, max=10000):
if not root:
return True
View diameterOfBinaryTree.go
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func max(a, b int) int {
if a < b {
View inorderTraversal.py
"""
Input: [1,null,2,3]
1
\
2
/
3
Output: [1,3,2]
"""
View abstractClass.java
import java.util.*
// Abstract class is only meant to serve as a base or blueprint for connecting the subclasses that inherit (extend) it.
// using a machine without knowing its internals
abstract class Book {
String title;
String author;
View getIntersectionNode.py
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
p1, p2 = headA, headB
while p1 or p2:
if p1 is p2:
return p1
p1 = headB if not p1 else p1.next
p2 = headA if not p2 else p2.next
You can’t perform that action at this time.