Skip to content

feat: add java solution to lc problem: No.1304 #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 2, 2021
Merged

feat: add java solution to lc problem: No.1304 #540

merged 9 commits into from
Aug 2, 2021

Conversation

0xcaffebabe
Copy link
Member

No description provided.

@0xcaffebabe 0xcaffebabe changed the title feat: add java solution to lc problem: No.1342 feat: add java solution to lc problem: No.1304 Aug 2, 2021
@yanglbme
Copy link
Member

yanglbme commented Aug 2, 2021

Hi @0xcaffebabe , I think the following code would be better :D

class Solution {
    public int[] sumZero(int n) {
        int preSum = 0;
        int[] ret = new int[n];
        for (int i = 1; i < n; ++i) {
            ret[i - 1] = i;
            preSum += i;
        }
        ret[n - 1] = -preSum;
        return ret;
    }
}

@yanglbme yanglbme merged commit b2ba3be into doocs:main Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants