Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions LRUCache/submission1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
class Node {
public:
int key;
int value;
Node * next;
Node * prev;
Node(int key, int value) {
this->key = key;
this->value = value;
next = NULL;
prev = NULL;
}
};

void insertNode(int key, int value, Node *start)
{
Node * p = start->next;
Node * q = new Node(key, value);
start->next = q;
q->prev = start;
q->next = p;
p->prev = q;
}

void deleteNode(Node *p)
{
Node *left = p->prev;
Node *right = p->next;
left->next = right;
right->prev = left;
delete p;
}

class LRUCache {
public:
int cap;
int n;
unordered_map<int, Node*> m;
Node * start;
Node * end;
LRUCache(int capacity) {
start = new Node(-1, -1);
end = new Node(-1, -1);
start->next = end;
end->prev = start;
cap = capacity;
n = 0;
}

int get(int key) {
if(m.find(key)==m.end())
return -1;
int v = m[key]->value;
deleteNode(m[key]);
m.erase(key);
insertNode(key, v, start);
m[key] = start->next;
return v;
}

void put(int key, int value) {
if(m.find(key)!=m.end())
{
int v = m[key]->value;
deleteNode(m[key]);
m.erase(key);
insertNode(key, value, start);
m[key] = start->next;
return;
}
if(n<cap)
{
insertNode(key, value, start);
m[key] = start->next;
n++;
}
else
{
Node * lru = end->prev;
m.erase(lru->key);
deleteNode(lru);
insertNode(key, value, start);
m[key] = start->next;
}
}
};

/**
* Your LRUCache object will be instantiated and called as such:
* LRUCache* obj = new LRUCache(capacity);
* int param_1 = obj->get(key);
* obj->put(key,value);
*/
103 changes: 69 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,82 @@
<h1 align="center">🚀 My LeetCode Journey</h1>
# Leetcode Problems 🚀

<p align="center">
<img src="https://img.shields.io/badge/Language-C++-blue?style=flat-square" />
<img src="https://img.shields.io/badge/LeetCode-Active🔥-orange?style=flat-square" />
<img src="https://img.shields.io/badge/Progress-Consistency🧠-green?style=flat-square" />
</p>
Welcome to the **Leetcode Problems** repository! This space is dedicated to showcasing all the accepted solutions I have crafted on the Leetcode platform. Whether you're preparing for coding interviews or just want to enhance your problem-solving skills, this repository is here to help you.

<p>
<img src="./__Assets/leetcode_profile.png"/>
</p>
[![Download Releases](https://img.shields.io/badge/Download%20Releases-blue.svg)](https://github.com/Gemechu-Asfaw/Leetcode-Problems/releases)

---
## Table of Contents

## 📌 About This Repository
- [Introduction](#introduction)
- [Topics Covered](#topics-covered)
- [Folder Structure](#folder-structure)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)

Welcome to my **LeetCode Solutions** repository!
This is where I regularly upload solutions to coding problems from [LeetCode](https://leetcode.com/).
You'll find my clean, optimized solutions mostly written in **C++** (some solutions may be submitted in python), with **well-commented code**.
## Introduction

---
Leetcode is a platform that offers a vast array of coding problems to help you sharpen your programming skills. This repository includes my solutions to various problems, organized by difficulty and topic. Each solution aims to be clear and efficient, showcasing different algorithms and data structures.

## 🧑‍💻 My LeetCode Live Stats
Feel free to explore the solutions and adapt them to your own coding style. You can find the latest releases of the solutions [here](https://github.com/Gemechu-Asfaw/Leetcode-Problems/releases). Download the files, execute them, and dive into the code!

![LeetCode Stats](https://leetcard.jacoblin.cool/ashokbhatt2048?ext=contest&theme=dark)
## Topics Covered

## 🏆 My LeetCode Badges
![LeetCode Stats](https://leetcode-badge-showcase.vercel.app/api?username=ashokbhatt2048&theme=dark&border=border&animated=true)
This repository includes solutions related to the following topics:

> 📅 I believe in solving at least 1 problem every day — consistency over intensity!
- **Algorithms**: Various sorting and searching algorithms, dynamic programming, and more.
- **Data Structures**: Implementations of arrays, linked lists, trees, graphs, and more.
- **Problem Solving**: Techniques to approach and solve coding challenges effectively.
- **Languages**: Solutions are provided in:
- C++
- JavaScript
- Python (Python3)
- Pandas (for data manipulation)

---
## Folder Structure

## 📂 Folder Structure
The repository is organized in a clear structure to help you navigate through the solutions easily:

```bash
📦LeetCode-Solutions/
├── TwoSum/
│ ├── submission1.cpp
│ ├── submission2.cpp
│ └── ...
├── AddTwoNumbers/
│ ├── submission1.cpp
│ ├── submission2.py
│ └── ...
├── README.md
└── ...
```
Leetcode-Problems/
├── C++/
│ ├── Easy/
│ ├── Medium/
│ └── Hard/
├── JavaScript/
│ ├── Easy/
│ ├── Medium/
│ └── Hard/
├── Python/
│ ├── Easy/
│ ├── Medium/
│ └── Hard/
└── Pandas/
└── Data_Manipulation/
```

Each language folder contains subfolders categorized by difficulty: Easy, Medium, and Hard. This organization allows you to find solutions based on your current skill level.

## Contributing

Contributions are welcome! If you have solutions or improvements to share, please follow these steps:

1. Fork the repository.
2. Create a new branch for your feature or fix.
3. Make your changes.
4. Submit a pull request.

Please ensure your code follows the same style and conventions as the existing solutions.

## License

This repository is licensed under the MIT License. Feel free to use the code for your own projects, but please provide appropriate credit.

## Contact

If you have any questions or feedback, feel free to reach out to me via GitHub or email. I’m always open to discussions about coding, algorithms, and problem-solving techniques.

Thank you for visiting the **Leetcode Problems** repository! Explore the solutions, enhance your skills, and happy coding! Don't forget to check the latest releases [here](https://github.com/Gemechu-Asfaw/Leetcode-Problems/releases).