mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										50
									
								
								23/04/1019.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								23/04/1019.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
struct ListNode
 | 
			
		||||
{
 | 
			
		||||
    int val;
 | 
			
		||||
    struct ListNode *next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct Pair {
 | 
			
		||||
    int first;
 | 
			
		||||
    int second;
 | 
			
		||||
} Pair;
 | 
			
		||||
 | 
			
		||||
int getLength(struct ListNode* head){
 | 
			
		||||
    int len = 0;
 | 
			
		||||
    ListNode* node = head;
 | 
			
		||||
    while (node.next)
 | 
			
		||||
    {
 | 
			
		||||
        node = node.next;
 | 
			
		||||
        len++;
 | 
			
		||||
    }
 | 
			
		||||
    return len;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int* nextLargerNodes(struct ListNode* head, int* returnSize){
 | 
			
		||||
    int len = 0;
 | 
			
		||||
    struct ListNode* cur = head;
 | 
			
		||||
    while (cur) {
 | 
			
		||||
        cur = cur->next;
 | 
			
		||||
        len++;
 | 
			
		||||
    }
 | 
			
		||||
    int* ans = (int *)calloc(len, sizeof(int));
 | 
			
		||||
    Pair stack[len];
 | 
			
		||||
    int top = 0, pos = 0;
 | 
			
		||||
 | 
			
		||||
    cur = head;
 | 
			
		||||
    int idx = -1;
 | 
			
		||||
    while (cur) {
 | 
			
		||||
        ++idx;
 | 
			
		||||
        ans[pos++] = 0;
 | 
			
		||||
        while (top > 0 && stack[top - 1].first < cur->val) {
 | 
			
		||||
            ans[stack[top - 1].second] = cur->val;
 | 
			
		||||
            top--;
 | 
			
		||||
        }
 | 
			
		||||
        stack[top].first = cur->val;
 | 
			
		||||
        stack[top].second = idx;
 | 
			
		||||
        top++;
 | 
			
		||||
        cur = cur->next;
 | 
			
		||||
    }
 | 
			
		||||
    *returnSize = len;
 | 
			
		||||
    return ans;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								23/04/2399.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								23/04/2399.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
bool checkDistances(char *s, int *distance, int distanceSize)
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < strlen(s); i++)
 | 
			
		||||
    {
 | 
			
		||||
        int site = s[i] - 'a';
 | 
			
		||||
        if (distance[i] == -1)
 | 
			
		||||
        {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        if (site + distance[i] + 1 >= strlen(s) || s[i] != s[i + distance[site] + 1])
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        distance[i] = -1;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user