Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
coding

Selim Ozturk selimslab

:octocat:
coding
View GitHub Profile
@selimslab
selimslab / get_gists.py
Last active Sep 25, 2020 — forked from leoloobeek/get_gists.py
Download all gists for a specific user
View get_gists.py
import sys
from subprocess import call
import json
import os
import requests
def download_gists(gists: list):
for gist in gists:
call(["git", "clone", gist["git_pull_url"]])
View Channels.go
Channels are a typed conduit through which you can send and receive values with the channel operator, <-.
ch <- v // Send v to channel ch.
v := <-ch // Receive from ch, and
// assign value to v.
(The data flows in the direction of the arrow.)
Like maps and slices, channels must be created before use:
View plusOne.go
func plusOne(digits []int) []int {
/*
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1:
View reverseBits.go
func reverseBits(num uint32) uint32 {
/*
Input: 00000010100101000001111010011100
Output: 00111001011110000010100101000000
*/
res := uint32(0)
power := uint32(31)
for num != 0 {
res += (num & 1) << power
num = num >> 1
View sortedArrayToBST.py
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
"""
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
Example:
Given the sorted array: [-10,-3,0,5,9],
View removeDuplicates1.py
def removeDuplicates(self, S: str) -> str:
"""
Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.
We repeatedly make duplicate removals on S until we no longer can.
Return the final string after all such duplicate removals have been made. It is guaranteed the answer is unique.
Example 1:
View heap.py
class KthLargest:
"""
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.
Your KthLargest class will have a constructor which accepts an integer k and an integer array nums, which contains initial elements from the stream. For each call to the method KthLargest.add, return the element representing the kth largest element in the stream.
Example:
int k = 3;
int[] arr = [4,5,8,2];
View minCostClimbingStairs.go
func minCostClimbingStairs(cost []int) int {
c1,c2 := cost[0], cost[1]
var min = func(a int,b int) int {
if a<b{
return a
}
return b
}
for i:=2; i<len(cost); i++{
View linked_list_deleteDuplicates.py
def deleteDuplicates(self, head: ListNode) -> ListNode:
"""
Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
Input: 1->1->2
Output: 1->2
Example 2:
View letterCasePermutation.py
def letterCasePermutation(self, S: str) -> List[str]:
"""
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.
Return a list of all possible strings we could create.
Examples:
Input: S = "a1b2"
Output: ["a1b2", "a1B2", "A1b2", "A1B2"]
Input: S = "3z4"
You can’t perform that action at this time.