摘要:
C语言代码: // 筛选出小于等于n的质数 for (i = 2; i * i <= n; i++) { if (a[i] == -1) continue; for (k = i; k * i < n; k++) { if (a[k * i] == -1) continue; a[k * i] = 阅读全文
摘要:
问题: 给定一个长度为n的整形数组,元素均大于0;以其中任意两个作为隔板,且位置不变;如何使水的容积最大?设计算法,说明时间、空间复杂度。 代码: int water(int a[], int n) { int m = 0, tmp; // m 存储最大值,作为最后的结果 int i = 0, j 阅读全文
摘要:
问题描述: 问题地址:https://leetcode-cn.com/problems/container-with-most-water/ 代码: public int maxArea(int[] height) { if (height.length <= 1) { return -1; } i 阅读全文
摘要:
简单的迭代法: int sqrt(int N) { for (int i = 1; i <= N / 2; i++) { if(i * i == N ) { return i; } if (i * i < N && (i + 1) * (i + 1) > N) { return i; } } } 折 阅读全文
摘要:
/** * Return the {@link FragmentActivity} this fragment is currently associated with. * May return {@code null} if the fragment is associated with a { 阅读全文