Skip to content

Instantly share code, notes, and snippets.

View ghadj's full-sized avatar
🤖

george hadjiantonis ghadj

🤖
View GitHub Profile
@ghadj
ghadj / Solution.java
Created November 18, 2024 20:59
Leetcode #1448
/**
* ---
* [https://leetcode.com/problems/count-good-nodes-in-binary-tree]
* 1448. Count Good Nodes in Binary Tree
* Given a binary tree root, a node X in the tree is named good if in the path from root to X
* there are no nodes with a value greater than X.
*
* Return the number of good nodes in the binary tree.
* ---
*/
@ghadj
ghadj / Solution.java
Created November 17, 2024 21:42
Leetcode #394
import java.util.Stack;
/**
* ---
* [https://leetcode.com/problems/decode-string]
* 394. Decode String
* Given an encoded string, return its decoded string.
*
* The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets
* is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
@ghadj
ghadj / Solution.java
Created November 14, 2024 21:18
Leetcode #735
/**
* ---
* [https://leetcode.com/problems/asteroid-collision]
* 735. Asteroid Collision
* We are given an array asteroids of integers representing asteroids in a row.
*
* For each asteroid, the absolute value represents its size, and the sign represents its
* direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
*
* Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller
@ghadj
ghadj / Solution.java
Created November 14, 2024 20:04
Leetcode #2390
/**
* ---
* [https://leetcode.com/problems/removing-stars-from-a-string]
* 2390. Removing Stars From a String
* You are given a string s, which contains stars *.
*
* In one operation, you can:
* - Choose a star in s.
* - Remove the closest non-star character to its left, as well as remove the star itself.
*
@ghadj
ghadj / Solution.java
Created November 13, 2024 21:20
Leetcode #2352
/**
* ---
* [https://leetcode.com/problems/equal-row-and-column-pairs]
* 2352. Equal Row and Column Pairs
* Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that
* row ri and column cj are equal.
*
* -not fully happy though-
* ---
*/
@ghadj
ghadj / SolutionA.java
Created November 12, 2024 21:14
Leetcode #1657
/**
* ---
* [https://leetcode.com/problems/determine-if-two-strings-are-close]
* 1657. Determine if Two Strings Are Close
* Two strings are considered close if you can attain one from the other using
* the following operations:
* - Operation 1: Swap any two existing characters.
* - Operation 2: Transform every occurrence of one existing character into
* another existing character,
* and do the same with the other character.
@ghadj
ghadj / Solution.java
Created November 11, 2024 21:05
Leetcode #1207
/**
* ---
* [https://leetcode.com/problems/unique-number-of-occurrences]
* 1207. Unique Number of Occurrences
* Given an array of integers arr, return true if the number of occurrences of each value in the
* array is unique or false otherwise.
* ---
*/
class Solution {
@ghadj
ghadj / Solution.java
Created November 10, 2024 16:41
Leetcode #1004
/**
* ---
* [https://leetcode.com/problems/max-consecutive-ones-iii]
* 1004. Max Consecutive Ones III
* Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the
* array if you can flip at most k 0's.
* ---
*/
class Solution {
@ghadj
ghadj / Solution.java
Created November 10, 2024 11:52
Leetcode #1493
/**
* ---
* [https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element]
* 1493. Longest Subarray of 1's After Deleting One Element
* ---
*/
class Solution {
public int longestSubarray(int[] nums) {
int prevSubArray = 0;
@ghadj
ghadj / Solution.java
Created November 10, 2024 09:58
Leetcode #1456
/**
* ---
* [https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length]
* 1456. Maximum Number of Vowels in a Substring of Given Length
* Given a string s and an integer k, return the maximum number of vowel letters in any substring
* of s with length k.
* ---
*/
class Solution {