VMware coding Challenge: Coin Toss Betting

技术分享

 1     static int CoinTossEndAmount(int betAmount, String coinTossResults) {
 2         if (betAmount <=0 || coinTossResults.length() == 0) return betAmount;
 3         long Amount = betAmount;
 4         long onebet = 1;
 5         for (int i=0; i<coinTossResults.length(); i++) {
 6             if (coinTossResults.charAt(i) == ‘H‘) {
 7                 Amount += onebet;
 8                 onebet *= 2;
 9             }
10             else {
11                 Amount -= onebet;
12                 onebet /= 2;
13             }
14             if (Amount < onebet) return 0;
15             if (onebet < 1) onebet = 1;
16         }
17         return (int)Amount;
18     }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。