Skip to content

Commit

Permalink
Added codes for 28 Feb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Feb 28, 2024
1 parent 1cb3fde commit 19750d7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
39 changes: 39 additions & 0 deletions GeeksForGeeks/February/28-2-24/GFG.java
Original file line number Diff line number Diff line change
@@ -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 ;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/February/28-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(1)
Space complecity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/February/28-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(h)
41 changes: 41 additions & 0 deletions LeetCode/February/28-2-24/Solution.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 19750d7

Please sign in to comment.