问题陈述:
给定一个数组,任务是将其分为两组S1和S2,以使它们的和之间的绝对差最小。
采样输入,
[1,6,5,11]=> 1。2个子集为{1,5,6}和{11},总和为12和11。因此答案是1。
[36,7,46,40]=> 23。2个子集为{7,46}和{36,40},总和为53和76。因此答案是23。
约束条件
1 <=数组大小<= 50
1 <= a [i] <= 50
我的努力:
int someFunction(int n, int *arr) {
qsort(arr, n, sizeof(int), compare);// sorted it for simplicity
int i, j;
int dp[55][3000]; // sum of the array won't go beyond 3000 and size of array is less than or equal …Run Code Online (Sandbox Code Playgroud) 给定一个数组,如
$x = array(array('a', 'aa'), array('b', 'bb'), array('c', 'cc'));
Run Code Online (Sandbox Code Playgroud)
有array_column返回
array_column($x, 0) === array('a', 'b', 'c')
or
array_column($x, 1) === array('aa', 'bb', 'cc')
Run Code Online (Sandbox Code Playgroud)
现在,有反面吗?一个可以做的功能:
array_putoneaftertheother(array('a', 'b', 'c'), array('aa', 'bb', 'cc')) === array(array('a', 'aa'), array('b', 'bb'), array('c', 'cc'))
Run Code Online (Sandbox Code Playgroud)
没有想到我...
实现起来很容易,但我很惊讶有这么array_*多功能,PHP 没有原生版本?!
我正在尝试利用队列,但队列正在重新组织,我不知道为什么
使用队列的每个人似乎都工作得很好,似乎没有人遇到这个问题
public static void main(String[] args){
PriorityQueue<String> cue = new PriorityQueue<String>();
cue.offer("this");
cue.offer("that");
cue.offer("then");
System.out.printf("%s \n", cue);
System.out.printf("%s \n", cue.peek());
cue.poll();
System.out.printf("%s \n", cue);
}
Run Code Online (Sandbox Code Playgroud)
我希望它打印:
[this, that, then]
this
[that, then]
Run Code Online (Sandbox Code Playgroud)
但相反它打印:
[that, this, then]
that
[then, this]
Run Code Online (Sandbox Code Playgroud)
我不知道为什么