-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC2938.java
More file actions
34 lines (27 loc) · 721 Bytes
/
LC2938.java
File metadata and controls
34 lines (27 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* LC2938
*/
import java.util.*;
public class LC2938 {
public static long minimumSteps(String s) {
int n = s.length();
long swapCount = 0;
int last = 0;
for (int cur = 0; cur < n; cur++) {
if (s.charAt(cur) == '0') { // White Ball
swapCount += (cur - last);
last++;
}
}
return swapCount;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the String Here : ");
String str = sc.nextLine();
System.out.println();
long ans = minimumSteps(str);
System.out.println(ans);
sc.close();
}
}