首页 > TAG信息列表 > returnSize

C练题笔记之:Leetcode-22. 括号生成

题目: 数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。 示例 1: 输入:n = 3 输出:["((()))","(()())","(())()","()(())","()()()"] 示例 2: 输入:n = 1 输出:["()"]   提示: 1 <= n <= 8 来源:力扣(LeetCode) 链接:https://le

【Leetcode】 C语言 228. Summary Ranges

Summary Ranges 题目分析:输出数组的连续排序的数字,如果有数字断档就再分接上后续的范围。利用两个指针分别指向连续的两个数字判断是否相差+1,再循环。 char ** summaryRanges(int* nums, int numsSize, int* returnSize){ char **ret = malloc(sizeof(char*)*20);

LeetCode 107. 二叉树的层序遍历 II

思路:在102题的基础上修改代码,增加一个反转就可以了。 int** levelOrderBottom(struct TreeNode* root, int* returnSize, int** returnColumnSizes){ *returnSize = 0; if(root==NULL) return NULL; int **res =malloc(sizeof(int*)*2000); *return

问题1 2021/11/26 未知格式

int** generate(int numRows, int* returnSize, int** returnColumnSizes){ int** a = malloc(sizeof(int*) * numRows); //int a[numRows+1][numRows+1]; *returnSize=numRows; *returnColumnSizes = malloc(sizeof(int) * numRows

两数之和I

两数之和** 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 示例: 输入:nums = [2

实现数组加一

题目来源于力扣–https://leetcode-cn.com/ 数组中的各个元素由0-9之间的数字组成,组成一个非负整数,包括0,9。除了0之外,不会有数字以0开头。数组的首位是数字的最高位,比如{1,2,3}加一操作后变成{1,2,4},{0}加一变成{1},{9}加一变成{1,0} 从数组末尾开始遍历数组,判断当前元素是不是9,如

#763 划分字母区间

/** * Note: The returned array must be malloced, assume caller calls free(). */ int* partitionLabels(char * s, int* returnSize){ int *result = (int *)malloc(sizeof(int) * strlen(s)); *returnSize = 0; int i; int rightIndex = -1; for(i

0144-二叉树的前序遍历

问题描述 https://leetcode-cn.com/problems/binary-tree-preorder-traversal/ 求解思路 递归: 在外层接口函数preorderTraversal()中申请空间并传递给核心的preorder()函数,在其中前序递归访问二叉树上的每一个节点。 使用栈迭代: //外层大循环: while(非空节点||栈非空){ //内

5.0 数据结构之排列与组合

编程总结 本篇参考liuyubobo 46. 全排列 思路:DFS /* 定义当前遍历深度count为全局变量 */ int gCount; void DFS(int *nums, int numsSize, int depth, int *path, int *visited, int **res) { // 递归终止条件,满足 depth == numSize if (depth == numsSize) { res[

力扣(LeetCode)刷题,简单+中等题(第34期)

目录 第1题:整数转罗马数字 第2题:电话号码的字母组合 第3题:二叉树的所有路径 第4题:砖墙 第5题:下一个排列 第6题:括号生成 第7题:删除并获得点数 第8题:全排列 第9题:颜色分类 第10题:字母异位词分组 力扣(LeetCode)定期刷题,每期10道题,业务繁重的同志可以看看我分享的思路,不是最高效解决

每日LeetCode - 66. 加一(C语言和Python 3)

  C语言 int* plusOne(int* digits, int digitsSize, int* returnSize){ for(int i=digitsSize-1;i>=0;i--){ if(digits[i]==9){ digits[i]=0; } else{ digits[i]++; *returnSize = digitsSize;

leetcode -- 15. 三数之和

题目 https://leetcode-cn.com/problems/3sum/ 给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。 注意:答案中不可以包含重复的三元组。 示例 1: 输入:nums = [-1,0,1,2,-1,-4] 输出:[[-1,-1,2],[-1

双指针的空间分配

参考leetcode15题: 其中参数 int** returnColumnSizes 表示返回数组中每一行的列数: 分配: *returnColumnSizes = (int*)malloc(numsSize * numsSize *sizeof(int)); 使用: (*returnColumnSizes)[*returnSize] = 3; /* 返回数组当前行的列数为3 */ 其中返回数组ret为

力扣566. 重塑矩阵-C语言实现-简单题

题目 传送门 在MATLAB中,有一个非常有用的函数 reshape,它可以将一个矩阵重塑为另一个大小不同的新矩阵,但保留其原始数据。 给出一个由二维数组表示的矩阵,以及两个正整数r和c,分别表示想要的重构的矩阵的行数和列数。 重构后的矩阵需要将原始矩阵的所有元素以相同的行遍历顺序填充。

leetcode-238-OK

address // 第一种解法,比较好,因为题目不让用除法,而第二种写之前没看清题目,所以用了除法 int* productExceptSelf(int* nums, int numsSize, int* returnSize){ returnSize[0] = numsSize; int* answer = (int *)malloc(sizeof(int) * numsSize); answer[0] = 1; for(int i

【leetcode】229. 求众数 II

  int* majorityElement(int* nums, int numsSize, int* returnSize){ int* res =(int*)calloc(2,sizeof(int)); *returnSize=0; if (nums == NULL || numsSize == 0) return res; // 初始化两个候选人candidate,和他们的计票 int cand1 = nums[0], count1 =

Leetcode 589. N叉树的前序遍历(DAY 3)

原题题目 代码实现 /** * Definition for a Node. * struct Node { * int val; * int numChildren; * struct Node** children; * }; */ /** * Note: The returned array must be malloced, assume caller calls free(). */ #define MAX 11000 v

【leetcode】131. 分割回文串

  void recursion(char* s,int* returnSize,int* col,int* oodhash,int* evenhash,int pst,int start,int len,char** temp,char*** arr){ if(start==len){ arr[(*returnSize)]=(char**)calloc(pst+1,sizeof(char*)); memcpy(arr[(*returnSize)],temp,si

【leetcode】102. 二叉树的层序遍历

  class Solution { public: vector<vector<int>> levelOrder(TreeNode* root) { vector <vector <int>> ret; if (!root) { return ret; } queue <TreeNode*> q; q.push(root);

【leetcode】48. 全排列 2

  int cmp(const void* a, const void* b){ return *(int*)a - *(int*)b; } void recursion(int* nums, int numsSize, int* returnSize, int* returnColumnSizes, int cnt, int** arr, int* temp, int* hash){ if (cnt == numsSize){ arr[(*returnSize)] =

【leetcode】39. 组合总和

  int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b; } void recursion(int* candidates,int len,int** arr, int* temp, int pst, int target, int res,int* returnSize,int* returnColumnSizes,int start){ for(int i=start; i<len &&a

【leetcode】18. 四数之和

  #define MAXLEN 50 int cmp(const void* a, const void* b){ return *(int*)a - *(int*)b; } int** fourSum(int* nums, int numsSize, int target, int* returnSize, int** returnColumnSizes){ int first=0, secend, left, right, temp; *returnSize=0;

【leetcode】17. 电话号码的字母组合

  void recursion(char * digits, int* returnSize,char** arr,char** map,int cur,char* s,int len){ if (cur >= len){ arr[(*returnSize)] = (char*)calloc(len + 1, sizeof(char)); strcat(arr[(*returnSize)++], s); return; }

【leetcode】1389. 按既定顺序创建目标数组

  /** * Note: The returned array must be malloced, assume caller calls free(). */ int* createTargetArray(int* nums, int numsSize, int* index, int indexSize, int* returnSize){ int* arr=(int*)calloc(numsSize,sizeof(int)); int i, j; for(i=0; i

【leetcode】面试题 16.11. 跳水板

  int* divingBoard(int shorter, int longer, int k, int* returnSize){ int val=longer-shorter,i; *returnSize=0; int* arr=(int*)calloc(k+1,sizeof(int)); if(k==0) return arr; arr[(*returnSize)++]=shorter*k; if(shorter==longe