登录
  • #美国面经
  • #码农类general
  • #面试经验
  • #linkedin

帮人答题Linkedin

zhenggao1986
2827
4
Given an array of positive integers and two players. In each turn, one player picks up one number and if the sum of all the picked up numbers is greater than a target number, the player wins. Write a program canIWin() to print the result. Answer: enum Result {Win, Lose, Draw} public class PickUpNumbers { public static Result canIWin(int[] numberPool, [b]int target) { if (target <= 0) return Result.Lose; boolean isEmpty = true; for (int data : numberPool) if (data > 0) isEmpty = false; if (isEmpty) return Result.Draw;[a[hide=188]

本帖隐藏的内容需要积分高于 188 才可浏览,点击前往一亩三分地论坛阅读

l2, 11)); int[] numberPool3 = {1, 2, 3, 4, 5, 6};[/align] System.out.println(PickUpNumbers.canIWin(numberPool3, 17));} Result: WinLoseDrawLose

Win
4条回复
热度排序

发表回复