Skip to content

Instantly share code, notes, and snippets.

View Ahmah2009's full-sized avatar
:electron:
Overthinking

Ahmad M ElShareif Ahmah2009

:electron:
Overthinking
View GitHub Profile
class Solution:
def climbStairs(self, n: int) -> int:
if n==0 or n==1 or n==2:
return n
m = n+1
step_n = [0] * m
step_n[0] = 0
step_n[1] = 1
@Ahmah2009
Ahmah2009 / deleteDuplicates.go
Created April 6, 2019 12:26
83. Remove Duplicates from Sorted List leetcode
func deleteDuplicates(head *ListNode) *ListNode {
if head == nil {
return head
}
node:=head
next := head.Next
for node!=nil && next!=nil{
if node.Val==next.Val{
temp := next
@Ahmah2009
Ahmah2009 / deleteDuplicates.go
Created April 6, 2019 11:51
82. Remove Duplicates from Sorted List II leetcode
func deleteDuplicates(head *ListNode) *ListNode {
if head == nil{
return head
}
tempNode := &ListNode{Val: head.Val-1, Next:head}
node:=tempNode
fast := tempNode.Next
for node.Next!=nil && fast.Next!=nil{
@Ahmah2009
Ahmah2009 / findAllConcatenatedWordsInADict.go
Created April 4, 2019 06:40
472. Concatenated Words leetcode
func findAllConcatenatedWordsInADict(words []string) []string {
res:= []string{}
mp:= make(map[string]int)
for _, word := range words {
mp[word] = 1
}
for _, word := range words {
delete(mp, word)
@Ahmah2009
Ahmah2009 / insert.go
Created April 4, 2019 06:27
57. Insert Interval leetcode
import "sort"
/**
* Definition for an interval.
* type Interval struct {
* Start int
* End int
* }
*/
func insert(intervals []Interval, newInterval Interval) []Interval {
@Ahmah2009
Ahmah2009 / kClosest.go
Created April 4, 2019 06:23
973. K Closest Points to Origin leetcode
import "sort"
func kClosest(points [][]int, K int) [][]int {
sort.SliceStable(points,func(i,j int)bool{
point1 := points[i]
point2 := points[j]
return distance(point1[0],point1[1]) < distance(point2[0],point2[1])
})
return points[:K]
}
@Ahmah2009
Ahmah2009 / solveEquation.go
Created April 4, 2019 06:20
640. Solve the Equation Leetcode
import "strings"
import "strconv"
func solveEquation(equation string) string {
eqnSides := strings.Split(equation, "=")
leftHandSide, rightHandSide := eqnSides[0], eqnSides[1]
lHV,lHx := getSideSum(leftHandSide)
rHV,rHx := getSideSum(rightHandSide)
if lHx == rHx && lHV == rHV{
@Ahmah2009
Ahmah2009 / reverseVowels.go
Created April 4, 2019 06:19
345. Reverse Vowels of a String leetCode
func reverseVowels(s string) string {
//A, E, I, O, and U
vowlesMap := map[byte]bool{
'a':true,'A':true,
'e': true,'E':true,
'i':true,'I':true,
'o':true,'O':true,
'u':true,'U':true}
vowlesValues := []byte{}
n:= 0
@Ahmah2009
Ahmah2009 / common-divisors.erl
Last active March 27, 2019 12:45
Hacker Rank problems solve by Erlang @Ahmah2009
%% https://www.hackerrank.com/challenges/common-divisors/submissions/code/13608658
% Enter your code here. Read input from STDIN. Print output to STDOUT
% Your class should be named solution
-module(solution).
-export([main/0]).
-compile(export_all).
main() ->
{ok,[A]}=io:fread("", "~d"),
scanner(A).
@Ahmah2009
Ahmah2009 / gist:e09d72ed6b2280b5c45e5eb568f1a743
Created November 8, 2018 11:14 — forked from dmytro/gist:7887843
Shell script for SYN flood DOS attacks prevention. Use sqlite3 to filter IP's
#!/bin/bash
SLEEP=120
MAX_CONN=20
MY_IP=0.0.0.0 # Configure your IP here
while true; do
(
echo "create table ips (ip string);"
echo 'begin transaction;'
netstat -an | grep -v ESTABLISHED | grep ${MY_IP}:80 | awk '{print $5}' | cut -f4 -d: | while read IP; do