Skip to content

Commit

Permalink
Added codes for 2 Feb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Feb 2, 2024
1 parent 2447c8e commit f1b4131
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
57 changes: 57 additions & 0 deletions GeeksForGeeks/February/2-2-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//{ Driver Code Starts
//Initial template for JAVA

import java.util.Scanner;

class aToi
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while(t>0)
{
String str = sc.nextLine();

Solution obj = new Solution();
int num = obj.atoi(str);

System.out.println(num);
t--;
}
}
}
// } Driver Code Ends


//User function template for JAVA

/*You are required to complete this method */
class Solution
{
int atoi(String s)
{
// Your code here
if(s.charAt(s.length()-1)=='-')
return -1;

for(int i=0;i<s.length();i++)
{
try
{
int a=Integer.parseInt(String.valueOf(s.charAt(i)));
}
catch(Exception e)
{
if(s.charAt(i)=='-')
continue;

else
return -1;
}
}

return Integer.parseInt(s);
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/February/2-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(log(high))
Space complexity - O(log(high))
2 changes: 2 additions & 0 deletions LeetCode/February/2-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(s)
Space complexity - O(1)
24 changes: 24 additions & 0 deletions LeetCode/February/2-2-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution
{
public List<Integer> sequentialDigits(int low, int high)
{
List<Integer> ans = new ArrayList<>();
Queue<Integer> q = new ArrayDeque<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));

while (!q.isEmpty())
{
int num = q.poll();
if (num > high)
return ans;

if (low <= num && num <= high)
ans.add(num);

int lastDigit = num % 10;
if (lastDigit < 9)
q.offer(num * 10 + lastDigit + 1);
}

return ans;
}
}

0 comments on commit f1b4131

Please sign in to comment.