Skip to content

Commit

Permalink
Added codes for 12 June
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jun 12, 2024
1 parent fcd9a48 commit dfe21d1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
40 changes: 40 additions & 0 deletions GeeksForGeeks/June/12-6-24/GFG.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/June/12-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(nlogn)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/June/12-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
30 changes: 30 additions & 0 deletions LeetCode/June/12-6-24/Solution.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

0 comments on commit dfe21d1

Please sign in to comment.