chiyeuemthoi
Senior Member
Cày mục đích để làm gì ấy chứ. Nếu để phỏng vấn thì làm gì thì làm phải cày cho bằng được 500 câu medium nhé fen.
sắp dc rồi , nma toàn đi copy
Cày mục đích để làm gì ấy chứ. Nếu để phỏng vấn thì làm gì thì làm phải cày cho bằng được 500 câu medium nhé fen.
function specialArray(nums: number[]): number {
nums.sort((a, b) => a - b)
const n = nums.length;
const bs = (num: number) => {
let l = 0, ans = nums.length, r = n - 1;
while (l <= r) {
let m = Math.floor((l + r) / 2);
if (nums[m] >= num) ans = m, r = m - 1;
else l = m + 1
}
return ans;
}
for (let i = 1; i <= n; i++) {
if (n - bs(i) === i) return i;
}
return -1;
};
public class Solution {
public int SpecialArray(int[] nums) {
int result = 0;
while(result <= nums.Length)
{
int count = 0;
for(int i = 0; i<nums.Length; i++)
{
if(nums[i] >= result)
{
count++;
}
if(count > result)
{
break;
}
}
if(count == result)
{
return result;
}
result++;
}
return -1;
}
}
class Solution {
public int specialArray(int[] nums) {
int res =-1;
Arrays.sort(nums);
int n = nums.length;
for(int i =1 ;i<=n;i++){
if(nums[n-i]>=i) {
res =i;
}
else if(nums[n-i]>=res){
return -1;
}
else break;
}
return res;
}
}
class Solution {
/**
* @param Integer[] $nums
* @return Integer
*/
function specialArray($nums) {
asort($nums); // sort array asc
$x = 0;
while ($x <= count($nums)) {
if ($x == count($nums)) return $x;
$nums = array_diff($nums, [$x]); // remove $x from array, we don't need to count it again
$x++;
}
return -1;
}
}
class Solution:
def specialArray(self, nums: List[int]) -> int:
size = len(nums)
freq = [0 for i in range(size + 1)]
for num in nums:
if num >= size:
freq[size] += 1
else:
freq[num] += 1
tmp = 0
for num in range(size, -1, -1):
tmp += freq[num]
if num == tmp:
return num
return -1
class Solution {
func specialArray(_ nums: [Int]) -> Int {
var newNums = nums
newNums.sort()
for (index, value) in newNums.enumerated() {
let x = newNums.count - index
if x <= value {
if index > 0 {
if x > newNums[index-1] {
return x
}
} else {
return x
}
}
}
return -1
}
}
class Solution:
def specialArray(self, nums: List[int]) -> int:
geCount = 0
n = len(nums)
frequency = Counter()
for num in nums:
if num > n:
geCount += 1
else:
frequency[num] += 1
for x in range(n, 0, -1):
geCount += frequency[x]
if x == geCount:
return x
if x < geCount:
break
return -1
copy sô lu sừn thì làm sao anh kì thị tiếp thu tri thức à?thấy fen 130 câu rồi mà, chắc trừ hao 30 câu copy solution phớ ko
public class Solution
{
public int SpecialArray(int[] nums)
{
Array.Sort(nums);
int n = nums.Length;
for (float i = 0.5f; i <= nums[^1]; i++)
{
int index = BinarySearch(nums, i);
if (index < 0)
{
index = ~index;
}
int roundVal = (int)i + 1;
if (roundVal == n - index)
{
return roundVal;
}
}
return -1;
}
private int BinarySearch(int[] nums, float search)
{
int left = 0;
int right = nums.Length;
while (left <= right)
{
int mid = left + (right - left) / 2;
float numMid = (float)nums[mid];
if (numMid < search)
{
left = mid + 1;
continue;
}
right = mid - 1;
}
if (left < nums.Length && search < nums[left])
{
return left;
}
return right;
}
}
Sắp của fen cũng nhiều phết đó
trừ bớt đống sqlthấy fen 130 câu rồi mà, chắc trừ hao 30 câu copy solution phớ ko
Fen thắng, fen thắng r, k cần solotrừ bớt đống sql
cuối tuần solo contest 400 k
may quá, bth làm dc có 2 câu thôi, làm liều gạ solo may mà bác ko nhậnFen thắng, fen thắng r, k cần solo
may quá, bth làm dc có 2 câu thôi, làm liều gạ solo may mà bác ko nhận
Thắng thua để rồi được gì đâu fen,
impl Solution {
pub fn special_array(mut nums: Vec<i32>) -> i32 {
let n = nums.len();
let ni = n as i32;
let mut freqs = vec![0i32; n + 1];
for num in nums {
if num >= ni {
freqs[n] += 1;
} else if num >= 0 {
freqs[num as usize] += 1;
}
}
let mut sum = 0;
for i in (0..=n).into_iter().rev() {
sum += freqs[i];
let ii = i as i32;
if ii == sum {
return ii;
}
}
-1
}
}
toi nhin nham 500bSắp của fen cũng nhiều phết đó