Skip to content

Commit bf66fff

Browse files
Added Silver and Gold Problem Solution in Java
1 parent ce3dd92 commit bf66fff

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

SilverAndGold.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public class SilverAndGold{
2+
//Silver and Gold Problem
3+
public static String flipCoins(int N,String s) {
4+
// Code here
5+
int count0, count1;
6+
count0 = count1 = 0;
7+
for(int i = 0;i < N;i++){
8+
int result = Character.compare('0',s.charAt(i));
9+
if(result == 0){
10+
count0++;
11+
}
12+
else{
13+
count1++;
14+
}
15+
}
16+
if(count0%2 == 0){
17+
return "Yes";
18+
}
19+
else{
20+
return "No";
21+
}
22+
}
23+
public static void main(String args[]){
24+
25+
System.out.println(flipCoins(8,"10010100"));//test case 1
26+
System.out.println(flipCoins(8,"11001100"));//test case 2
27+
System.out.println(flipCoins(2,"00"));//test case 2
28+
29+
30+
31+
32+
}
33+
}
34+
35+
36+
37+

0 commit comments

Comments
 (0)