Created
September 2, 2017 17:25
-
-
Save cixuuz/786cb318ef08113a097d84b77ab2f478 to your computer and use it in GitHub Desktop.
[553. Optimal Division] #leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
// O(n) O(n) | |
public String optimalDivision(int[] nums) { | |
StringBuilder sb = new StringBuilder(); | |
sb.append(nums[0]); | |
for (int i = 1; i < nums.length; i++) { | |
sb.append("/"); | |
if (i == 1 && nums.length>2) { | |
sb.append("("); | |
} | |
sb.append(nums[i]); | |
} | |
return nums.length>2? sb.append(")").toString() : sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment