Skip to content

Commit

Permalink
Added solution_java.java for day15
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-09 authored Oct 15, 2024
1 parent 43eeead commit 3d41740
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions solutions/day15/solution_java.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public long minimumSteps(String s) {
int i = s.length() - 1;
long minOps = 0;
while(i>= 0 && s.charAt(i) == '1') {
i--;
}
if(i == -1) {
return minOps;
}
int zeroIndex = i;
while(i >= 0) {
if(s.charAt(i) == '1') {
minOps += zeroIndex - i;
zeroIndex--;
}
i--;
}
return minOps;
}
}

0 comments on commit 3d41740

Please sign in to comment.