牛牛想把中的自然数分别放到两个集合中,但是他想使这两个集合中元素之和的差的绝对值最小,牛牛不知道该怎么做,所以他想请你帮忙。 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少?
示例1
输入
2
输出
1
说明
分成两个集合,其中的元素分别为1和2,那么其差为1。
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ public int findNumber (int n) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ int findNumber(int n) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? # @param n int整型 代表题意中的n # @return int整型 # class Solution: def findNumber(self , n ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ public int findNumber (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ function findNumber( n ) { // write code here } module.exports = { findNumber : findNumber };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? # @param n int整型 代表题意中的n # @return int整型 # class Solution: def findNumber(self , n ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ func findNumber( n int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ int findNumber(int n ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? # @param n int整型 代表题意中的n # @return int整型 # class Solution def findNumber(n) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ def findNumber(n: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ fun findNumber(n: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ public int findNumber (int n) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ export function findNumber(n: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ func findNumber ( _ n: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 给定一个数n,返回分成两个集合后,这两个集合中元素之和的差的绝对值最小是多少? * @param n int整型 代表题意中的n * @return int整型 */ pub fn findNumber(&self, n: i32) -> i32 { // write code here } }
2
1