-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cb3fde
commit 19750d7
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(1) | ||
Space complecity - O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |