diff --git a/Contains-Duplicate/solution.py b/Contains-Duplicate/solution.py new file mode 100644 index 0000000..a03f3a2 --- /dev/null +++ b/Contains-Duplicate/solution.py @@ -0,0 +1,11 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + + hash_set = set() + + for num in nums: + if num in hash_set: + return True + else: + hash_set.add(num) + return False \ No newline at end of file diff --git a/README.md b/README.md index d922b9d..40db3ea 100644 --- a/README.md +++ b/README.md @@ -1,148 +1,9 @@ -# GitHub Guide for Submitting Challenge Solutions - -Welcome to the GitHub repository for coding challenges! This guide will walk you through the process of creating a branch under your name and uploading your solution files step by step. If you are new to Git and GitHub, follow these instructions carefully. +# We Code Blind 75 Challenge --- -## πŸš€ Setting Up Git and GitHub - -### 1️⃣ Install Git -If you haven't installed Git yet, download and install it from [Git's official website](https://git-scm.com/downloads). - -### 2️⃣ Create a GitHub Account -If you don’t have a GitHub account, create one at [GitHub](https://github.com/). - -### 3️⃣ Fork the Repository -1. Go to the repository URL shared by your instructor. -2. Click on the **Fork** button in the top-right corner to create a copy in your GitHub account. - -### 4️⃣ Clone the Repository Locally -1. Open **Terminal** (Linux/macOS) or **Command Prompt/Powershell** (Windows). -2. Run the following command, replacing `your-username` with your GitHub username: - - ```sh - git clone https://github.com/WeCode-Community-Dev/blind-75-challenge.git - ``` - -3. Navigate into the repository folder: - - ```sh - cd blind-75-challenge - ``` - ---- - -## 🌿 Creating a Branch Under Your Name -Each student must create a separate branch with their name before making any changes. - -1. Check the current branches: - - ```sh - git branch - ``` - -2. Create a new branch with your name (make sure this is unique - add some unique number or characters to make sure it is not already there): - - ```sh - git checkout -b your-branch-name - ``` - -3. Verify the branch was created and switched to it: - - ```sh - git branch - ``` - - Your name should now be highlighted, meaning you are on that branch. - ---- - -## πŸ” Setting Upstream and Pulling Latest Changes -Before working on a new challenge, ensure your repository is up to date. - -1. Add the original repository as the upstream remote (only required once): - - ```sh - git remote add upstream https://github.com/WeCode-Community-Dev/blind-75-challenge.git - ``` - -2. Fetch the latest changes: - - ```sh - git fetch upstream - ``` - -3. Merge the latest changes into your branch: - - ```sh - git merge upstream/main - ``` - ---- - -## ✏️ Adding Your Challenge Solution -Upload only the solution file for each challenge (e.g., `solution.py`, `solution.cpp`, `solution.java`). -you can name the file .py or .cpp or .java etc. -example: two-sum.py or two-sum.cpp or two-sum.java as per the programming language you choose - -1. Navigate to the folder for the challenge you are working on. -2. Place your solution file inside the appropriate challenge folder. - -Example structure: - -``` -repository-name/ -β”‚-- Challenge-1/ -β”‚ β”‚-- solution.py # Your file -β”‚-- Challenge-2/ -β”‚ β”‚-- solution.cpp # Another file -``` - ---- - -## πŸ“€ Committing and Pushing Your Code - -Replace the "challenge-1" with problem name - -1. Add the file you modified: - - ```sh - git add Challenge-1/solution.py - ``` - -2. Commit your changes with a meaningful message: - - ```sh - git commit -m "Added solution for Challenge 1" - ``` - -3. Push your branch to your GitHub repository: - - ```sh - git push origin your-branch-name - ``` - ---- - -## πŸ”„ Creating a Pull Request (Not Required) -Once you've pushed your changes, you need to create a **Pull Request (PR)**. - -1. Go to your GitHub repository. -2. Switch to your branch (`your-branch-name`). -3. Click on **Compare & pull request**. -4. Add a meaningful **title** and **description**. -5. Click **Create pull request**. - -Your code will now be reviewed and merged by the instructor! πŸŽ‰ - ---- - -## ❗ Important Rules -βœ… Always create a branch under your name. -βœ… Upload only the solution file (no unnecessary files or folders). -βœ… Keep your repository updated by pulling the latest changes. -βœ… Use meaningful commit messages. -βœ… Create a pull request for every challenge. +## About +# Name: Libin T +# Email: libinthankayathil@gmail.com Happy coding! πŸš€ - diff --git a/best-time-to-buy-and-sell-stocks/solution.py b/best-time-to-buy-and-sell-stocks/solution.py new file mode 100644 index 0000000..12b3d01 --- /dev/null +++ b/best-time-to-buy-and-sell-stocks/solution.py @@ -0,0 +1,14 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + # Two-Pointer + left, right = 0, 1 + profit = 0 + + while right < len(prices): + if prices[right] > prices[left]: + profit = max(profit, prices[right] - prices[left]) + else: + left = right + + right += 1 + return profit diff --git a/two-sum/two-sum.py b/two-sum/two-sum.py new file mode 100644 index 0000000..1ff27e1 --- /dev/null +++ b/two-sum/two-sum.py @@ -0,0 +1,6 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + for i in range(len(nums)): + for j in range(len(nums)): + if nums[j] == target - nums[i] and i != j: + return [i, j]