mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										22
									
								
								23/07/2208.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								23/07/2208.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <queue>
 | 
			
		||||
#include <numeric>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Solution {
 | 
			
		||||
        public:
 | 
			
		||||
        int halveArray(vector<int>& nums) {
 | 
			
		||||
            priority_queue<double> pq(nums.begin(), nums.end());
 | 
			
		||||
            int res = 0;
 | 
			
		||||
            double sum = accumulate(nums.begin(), nums.end(), 0.0), sum2 = 0.0;
 | 
			
		||||
            while (sum2 < sum / 2) {
 | 
			
		||||
                double x = pq.top();
 | 
			
		||||
                pq.pop();
 | 
			
		||||
                sum2 += x / 2;
 | 
			
		||||
                pq.push(x / 2);
 | 
			
		||||
                res++;
 | 
			
		||||
            }
 | 
			
		||||
            return res;
 | 
			
		||||
        }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										22
									
								
								23/07/2500.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								23/07/2500.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <queue>
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Solution {
 | 
			
		||||
public:
 | 
			
		||||
    int deleteGreatestValue(vector<vector<int>>& grid) {
 | 
			
		||||
        int m = grid.size(), n = grid[0].size();
 | 
			
		||||
        for (int i = 0; i < m; i++) {
 | 
			
		||||
            sort(grid[i].begin(), grid[i].end());
 | 
			
		||||
        }
 | 
			
		||||
        int res = 0;
 | 
			
		||||
        for (int j = 0; j < n; j++) {
 | 
			
		||||
            int mx = 0;
 | 
			
		||||
            for (int i = 0; i < m; i++) {
 | 
			
		||||
                mx = max(mx, grid[i][j]);
 | 
			
		||||
            }
 | 
			
		||||
            res += mx;
 | 
			
		||||
        }
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										55
									
								
								23/07/771.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								23/07/771.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
#include "math.h"
 | 
			
		||||
#include "stdio.h"
 | 
			
		||||
 | 
			
		||||
// 未验证,leecode使用了 uthash.h 库进行处理
 | 
			
		||||
typedef struct linked {
 | 
			
		||||
    char val;
 | 
			
		||||
    struct linked *next;
 | 
			
		||||
} *HashTable;
 | 
			
		||||
 | 
			
		||||
HashTable *createTable(int hashCode, const char *jewels) {
 | 
			
		||||
    HashTable table[hashCode];
 | 
			
		||||
    for (int i = 0; i < sizeof(jewels) / sizeof(jewels[0]); ++i) {
 | 
			
		||||
        int temp = jewels[i] % hashCode;
 | 
			
		||||
        struct linked link = {jewels[i], NULL};
 | 
			
		||||
        if (table[temp] == NULL) {
 | 
			
		||||
            table[temp] = &link;
 | 
			
		||||
        } else {
 | 
			
		||||
            HashTable temps = table[temp];
 | 
			
		||||
            if (temps->val == jewels[i]) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            while (temps->next != NULL) {
 | 
			
		||||
                temps = temps->next;
 | 
			
		||||
                if (temps->val == jewels[i]) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            temps->next = &link;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return table;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int contained(char x, HashTable *table, int hashCode) {
 | 
			
		||||
    int temp = x % hashCode;
 | 
			
		||||
    HashTable temps = table[temp];
 | 
			
		||||
    while (temps){
 | 
			
		||||
        if (temps->val == x){
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int numJewelsInStones(char *jewels, char *stones) {
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    int hashCode = (int) sqrt(sizeof(jewels) / sizeof(jewels[0])) + 1;
 | 
			
		||||
    HashTable *table = createTable(hashCode, jewels);
 | 
			
		||||
    for (int i = 0; i < sizeof(stones) / sizeof(stones[0]); ++i) {
 | 
			
		||||
        if (contained(stones[i], table, hashCode)) {
 | 
			
		||||
            count++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user