-
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
fcd9a48
commit dfe21d1
Showing
4 changed files
with
74 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,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; | ||
} | ||
} |
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(nlogn) | ||
Space complexity - 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(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,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; | ||
} | ||
} | ||
} | ||
} |