Skip to content

Commit

Permalink
Merge pull request #78 from Shubham-09/main
Browse files Browse the repository at this point in the history
Added solution_java.java for day15
  • Loading branch information
arya2004 authored Oct 15, 2024
2 parents 43eeead + 3d41740 commit ecbfe87
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 ecbfe87

Please sign in to comment.