# O(n) very easy Java solution.

• ``````public class Solution {
public String optimalDivision(int[] nums) {
StringBuilder builder = new StringBuilder();
builder.append(nums[0]);
for (int i = 1; i < nums.length; i++) {
if (i == 1 && nums.length > 2) {
builder.append("/(").append(nums[i]);
} else {
builder.append("/").append(nums[i]);
}
}

return nums.length > 2 ? builder.append(")").toString() : builder.toString();
}
}
``````

• @Chengpengli You can check the leetcode article - https://leetcode.com/articles/optimal-division/
It's about division and operator precedence. The result will always be of the form `a/(b/c/d)`.

While this is a really nice solution for this problem, I would still go ahead with the other solutions since that's more helpful in solving other similar problems for the interviews.

• really nice solution for this

Thanks~!!!!

• How about the case like
`[1000,2,3]`

The solution give the the result to be
`1000/(2/3)`

So i guess, we are not talking about integer division here?

• @rjtsdl Of course not. We aren't talking about integer division, we are talking about float division as written in the problem statement "Given a list of positive integers, the adjacent integers will perform the `float division`" .

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.