diff --git a/GeeksForGeeks/June/12-6-24/GFG.java b/GeeksForGeeks/June/12-6-24/GFG.java new file mode 100644 index 0000000..5f205a6 --- /dev/null +++ b/GeeksForGeeks/June/12-6-24/GFG.java @@ -0,0 +1,40 @@ +//{ Driver Code Starts +import java.io.*; +import java.util.*; + +class GFG { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t; + t = Integer.parseInt(br.readLine()); + while (t-- > 0) { + + int n; + n = Integer.parseInt(br.readLine()); + + Solution obj = new Solution(); + int res = obj.countNumberswith4(n); + + System.out.println(res); + } + } +} + +// } Driver Code Ends + + + +class Solution +{ + public static int countNumberswith4(int n) + { + // code here + int c=0; + for(int i=0;i<=n;i++) + { + if(String.valueOf(i).contains("4")) + c++; + } + return c; + } +} diff --git a/GeeksForGeeks/June/12-6-24/README.md b/GeeksForGeeks/June/12-6-24/README.md new file mode 100644 index 0000000..60370eb --- /dev/null +++ b/GeeksForGeeks/June/12-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(nlogn) +Space complexity - O(1) diff --git a/LeetCode/June/12-6-24/README.md b/LeetCode/June/12-6-24/README.md new file mode 100644 index 0000000..9567f26 --- /dev/null +++ b/LeetCode/June/12-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(1) diff --git a/LeetCode/June/12-6-24/Solution.java b/LeetCode/June/12-6-24/Solution.java new file mode 100644 index 0000000..4d81f8d --- /dev/null +++ b/LeetCode/June/12-6-24/Solution.java @@ -0,0 +1,30 @@ +class Solution { + public void sortColors(int[] nums) { + // 1ms solution + // Arrays.sort(nums); + + // 0ms solution + int zero = -1; + int one = -1; + int two = -1; + + for (int num : nums) + { + if (num == 0) + { + nums[++two] = 2; + nums[++one] = 1; + nums[++zero] = 0; + } + else if (num == 1) + { + nums[++two] = 2; + nums[++one] = 1; + } + else + { + nums[++two] = 2; + } + } + } +}