Skip to content

Instantly share code, notes, and snippets.

View Ifihan's full-sized avatar
🔧
Work in Progress

Ifihanagbara Olusheye Ifihan

🔧
Work in Progress
View GitHub Profile
@Ifihan
Ifihan / app.py
Last active August 19, 2020 03:32
Using Flask-RESTful to build a basic REST API
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Student(Resource):
def get(self, name):
return {"student": name}
@Ifihan
Ifihan / main.py
Created December 16, 2021 17:35
Cross-over genetic algorithm implementation in Python
import random
# prb_score = int(input("Enter the probability score: "))
def cross_over(parent1, parent2):
child1 = []
child2 = []
for i in range(len(parent1)):
if random.random() < 0.5:
child1.append(parent1[i])
child2.append(parent2[i])
@Ifihan
Ifihan / main.py
Created December 16, 2021 17:37
Mutation algorithm implementation in Python
import random
def mutation(individual, mutation_rate):
for i in range(len(individual)):
if random.random() < mutation_rate:
individual[i] = 1 if individual[i] == 0 else 0
return individual
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums) - 1):
for j in range(i + 1, len(nums)):
if nums[i] + nums[j] == target:
return i,j
@Ifihan
Ifihan / text.md
Created May 12, 2022 07:18
47. Permutations II

Permutations II

This is a follow up problem from Permutations. This goal of this problem is to return all possible unique results from the input of an array.

Solution

The solution I followed was Backtracking. Looks like a DFS (Depth-First Search) problem 🤔

Create a hashmap to take count of all number to leave have a non-reapeating digit or eliminate duplicate. Then the bactrack the decision tree.

@Ifihan
Ifihan / lorenzattractor.jl
Last active March 13, 2023 17:06
Demo for Lorenz Attractor from the Plots.jl documentation
using Plots
# define the Lorenz attractor
Base.@kwdef mutable struct Lorenz
dt::Float64 = 0.02
σ::Float64 = 10
ρ::Float64 = 28
β::Float64 = 8/3
x::Float64 = 1
y::Float64 = 1
z::Float64 = 1
@Ifihan
Ifihan / read.md
Created May 18, 2023 22:16
1. Two Sum

Two Sum

Question on Leetcode - Easy

Approach

There were three approaches taken to solve this question.

  1. Use of two for-loops.
  2. I call it the x = z - y (from the equation x + y = z).
  3. Two pointer approach.

The two pointer approach was the approach used. In this approach, the array is first sortted from the lowest to the highest number.

@Ifihan
Ifihan / main.md
Created May 25, 2023 21:38
Search Insert Position

Search Insert Position

Question on Leetcode - Easy

Approach

The approach taken was the binary search to find the target. I initialized two pointers, left and right at the beginning and end of the array respectfully. Then I used a while loop left < right. Then in the loop, I calculate the mid and compare it to the target. If the mid is the target, I return mid. If the mid is less than the target, I add a unit step to the left and if the mid is grater than one, I remove a unit step from the

@Ifihan
Ifihan / main.md
Created May 29, 2023 22:11
Merge Two Sorted Lists

21. Merge Two Sorted Lists

Question: Leetcode - Easy

Approach

The approach to use two pointers: The first one was a dummy ListNode() and the second is a tail. Then I traverse throught the list by appending the smaller values of either lists in the tail pointer.

Once the end of the list is gotten to, I then append the remaining nodes to the linked list.

@Ifihan
Ifihan / main.md
Created June 21, 2023 10:45
Is Subsequence

Is Subsequence

Question on Leetcode - Easy

Approach

The approach taken was to use a pointer intialized at 0, for the sequence s string. This pointer servers as a counter which the increases for every positive match against the main string. Afterwards, I traversed through the main string t and returned the a boolean of if the pointer value was the same as the length of the sequence s.

Code

class Solution: