From 1b53c786c5e09f20d0a8c2a72042068bf0ce0597 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Fri, 14 Jun 2024 11:18:41 +0530 Subject: [PATCH] Added codes for 14 June --- GeeksForGeeks/June/14-6-24/GFG.java | 37 ++++++++++++++++++++++++++++ GeeksForGeeks/June/14-6-24/README.md | 2 ++ LeetCode/June/14-6-24/README.md | 2 ++ LeetCode/June/14-6-24/Solution.java | 18 ++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 GeeksForGeeks/June/14-6-24/GFG.java create mode 100644 GeeksForGeeks/June/14-6-24/README.md create mode 100644 LeetCode/June/14-6-24/README.md create mode 100644 LeetCode/June/14-6-24/Solution.java diff --git a/GeeksForGeeks/June/14-6-24/GFG.java b/GeeksForGeeks/June/14-6-24/GFG.java new file mode 100644 index 0000000..3dabf23 --- /dev/null +++ b/GeeksForGeeks/June/14-6-24/GFG.java @@ -0,0 +1,37 @@ +//{ Driver Code Starts +//Initial Template for Java +import java.util.*; +import java.io.*; +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) { + int n = Integer.parseInt(read.readLine()); + Solution ob = new Solution(); + + System.out.println(ob.armstrongNumber(n)); + } + } +} +// } Driver Code Ends + + +//User function Template for Java +class Solution +{ + static String armstrongNumber(int n) + { + // code here + int x = n; + int result = 0; + while(x > 0) + { + result += Math.pow((x%10), 3); + x = x/10; + } + + return result==n ? "Yes":"No"; + } +} diff --git a/GeeksForGeeks/June/14-6-24/README.md b/GeeksForGeeks/June/14-6-24/README.md new file mode 100644 index 0000000..9567f26 --- /dev/null +++ b/GeeksForGeeks/June/14-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(1) diff --git a/LeetCode/June/14-6-24/README.md b/LeetCode/June/14-6-24/README.md new file mode 100644 index 0000000..c826120 --- /dev/null +++ b/LeetCode/June/14-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n*logn) +Space complexity - O(1) diff --git a/LeetCode/June/14-6-24/Solution.java b/LeetCode/June/14-6-24/Solution.java new file mode 100644 index 0000000..3b353c7 --- /dev/null +++ b/LeetCode/June/14-6-24/Solution.java @@ -0,0 +1,18 @@ +class Solution +{ + public int minIncrementForUnique(int[] nums) + { + int ans = 0; + int min = 0; + + Arrays.sort(nums); + + for (int num : nums) + { + ans += Math.max(min - num, 0); + min = Math.max(min, num) + 1; + } + + return ans; + } +}