From 19750d7e8d23b2b5d131232f8f447753db64d9c0 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Wed, 28 Feb 2024 12:06:25 +0530 Subject: [PATCH] Added codes for 28 Feb --- GeeksForGeeks/February/28-2-24/GFG.java | 39 ++++++++++++++++++++++ GeeksForGeeks/February/28-2-24/README.md | 2 ++ LeetCode/February/28-2-24/README.md | 2 ++ LeetCode/February/28-2-24/Solution.java | 41 ++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 GeeksForGeeks/February/28-2-24/GFG.java create mode 100644 GeeksForGeeks/February/28-2-24/README.md create mode 100644 LeetCode/February/28-2-24/README.md create mode 100644 LeetCode/February/28-2-24/Solution.java diff --git a/GeeksForGeeks/February/28-2-24/GFG.java b/GeeksForGeeks/February/28-2-24/GFG.java new file mode 100644 index 0000000..c37ffd0 --- /dev/null +++ b/GeeksForGeeks/February/28-2-24/GFG.java @@ -0,0 +1,39 @@ +//{ Driver Code Starts +//Initial Template for Java + +import java.io.*; +import java.util.*; + +class GFG { + public static void main(String args[]) throws IOException { + BufferedReader read = + new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(read.readLine()); + while (t-- > 0) { + String S=read.readLine(); + Solution ob = new Solution(); + System.out.println(ob.DivisibleByEight(S)); + } + } +} +// } Driver Code Ends + + +//User function Template for Java + +class Solution{ + int DivisibleByEight(String s) + { + //code here + if ( s.length() >= 3 ) + { + String last3 = s.substring( s.length()-3 ); + int val = Integer.parseInt(last3); + + return ( val == 0 || val % 8 == 0 ) ? 1 : -1 ; + } + + int v = Integer.parseInt(s); + return ( v == 0 || v % 8 == 0 ) ? 1 : -1 ; + } +} diff --git a/GeeksForGeeks/February/28-2-24/README.md b/GeeksForGeeks/February/28-2-24/README.md new file mode 100644 index 0000000..2186fbc --- /dev/null +++ b/GeeksForGeeks/February/28-2-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(1) +Space complecity - O(1) diff --git a/LeetCode/February/28-2-24/README.md b/LeetCode/February/28-2-24/README.md new file mode 100644 index 0000000..722dfdc --- /dev/null +++ b/LeetCode/February/28-2-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(h) diff --git a/LeetCode/February/28-2-24/Solution.java b/LeetCode/February/28-2-24/Solution.java new file mode 100644 index 0000000..ed94077 --- /dev/null +++ b/LeetCode/February/28-2-24/Solution.java @@ -0,0 +1,41 @@ +/** + * Definition for a binary tree node. + * public class TreeNode { + * int val; + * TreeNode left; + * TreeNode right; + * TreeNode() {} + * TreeNode(int val) { this.val = val; } + * TreeNode(int val, TreeNode left, TreeNode right) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +class Solution +{ + public int findBottomLeftValue(TreeNode root) + { + dfs(root, 1); + return ans; + } + + private int ans = 0; + private int maxDepth = 0; + + private void dfs(TreeNode root, int depth) + { + if (root == null) + return; + + if (depth > maxDepth) + { + maxDepth = depth; + ans = root.val; + } + + dfs(root.left, depth + 1); + dfs(root.right, depth + 1); + } +}