刷题日记
先敲棋子后吃瓜
it爱好者
展开
-
LeetCode刷题日记(50. Pow(x, n))
50. Pow(x, n)double QuickMuti(double x, long int n) { if (n == 0) return 1.0; double y = QuickMuti(x, n/2); return n % 2 == 0 ? y * y : y * y * x;}double myPow(double x, int n) { long int N = n; double ans = n < 0 ? 1.0原创 2021-10-30 00:00:39 · 95 阅读 · 0 评论 -
刷题日记(6. Z 字形变换)
6. Z 字形变换#define ElementType charstruct MNode;typedef struct MNode* PtrToMNode;typedef PtrToMNode Vector;typedef PtrToMNode rPosition;typedef PtrToMNode bPosition;void bInsert(bPosition B);void PrintVector(Vector V);Vector CreateVector(int ro原创 2021-10-28 23:55:18 · 136 阅读 · 0 评论 -
LeetCode(34. 在排序数组中查找元素的第一个和最后一个位置)
34. 在排序数组中查找元素的第一个和最后一个位置/** * Note: The returned array must be malloced, assume caller calls free(). */int* searchRange(int* nums, int numsSize, int target, int* returnSize){ *returnSize = 2; int *res = calloc(2, sizeof(int)); res[0] =原创 2021-10-27 23:32:02 · 72 阅读 · 0 评论 -
LeetCode刷题日记(21. 合并两个有序链表)
21. 合并两个有序链表/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){ if (!l1 && !l2) return NULL;原创 2021-10-26 21:34:28 · 112 阅读 · 0 评论 -
刷题日记(19. 删除链表的倒数第 N 个结点)
19. 删除链表的倒数第 N 个结点/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* removeNthFromEnd(struct ListNode* head, int n){ struct ListNode *dummy = malloc(sizeof(struc原创 2021-10-25 22:55:16 · 63 阅读 · 0 评论 -
LeetCode刷题日记(48. 旋转图像)
48.旋转图像/** * @param {number[][]} matrix * @return {void} Do not return anything, modify matrix in-place instead. */var rotate = function(matrix) { N = matrix.length if (N==1) return t = new Array(N*N) for (i=0; i<matrix.length; ..原创 2021-10-24 23:43:44 · 1492 阅读 · 0 评论 -
LeetCode刷题日记(1.两数之和)
两数之和暴力解法/** * Note: The returned array must be malloced, assume caller calls free(). */int* twoSum(int* nums, int numsSize, int target, int* returnSize){ int *res = calloc(2, sizeof(int)); for (int i=0; i<numsSize; i++) { for (in原创 2021-10-23 22:54:25 · 60 阅读 · 0 评论 -
LeetCode刷题日记(007.回文数)
007.回文数bool isPalindrome(int x){ if (x < 0) return 0; int num = x; int rev = 0; while (num >= 10) { rev = rev * 10 + num % 10; num /= 10; } return (rev == x / 10) && (num == (x % 10));}题目比较简单,借鉴了昨原创 2021-10-22 19:27:15 · 478 阅读 · 0 评论 -
LeetCode刷题日记(7. 整数反转)
7.整数反转int reverse(int x) { if (x == 0) return x; // 之所以单独处理这个是因为此时-x溢出了会报错 if (x == -2147483648) return 0; int neg, num; neg = x < 0 ? -1 : 1; num = x < 0 ? -x : x; int N = (int)log10(num) + 1; // 位数 int *arr = c原创 2021-10-21 22:50:27 · 292 阅读 · 0 评论 -
LeetCode刷题日记(4. 寻找两个正序数组的中位数)
4. 寻找两个正序数组的中位数double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){ int length = nums1Size + nums2Size; int *arr= calloc(length, sizeof(int)); int i = 0, j = 0; while (1) { if (i < nums1Size &原创 2021-10-20 21:18:27 · 68 阅读 · 0 评论 -
LeetCode刷题日记(3. 无重复字符的最长子串)
3.无重复字符的最长字串int lengthOfLongestSubstring(char *s){ int hash[128] = { 0 }; int length = strlen(s); int maxLen = 0; int curr = 0; if (length <= 1) return length; for (int ii=0; ii<length; ii++) { for (int i=ii; i<原创 2021-10-19 17:50:34 · 138 阅读 · 0 评论 -
LeetCode刷题日记(写在开头自勉)
从今天开始,每天(至少)一道题全年无休,没有节假日,直到找到工作!我以前总是做的很快,想要在短时间内学会某个东西,可我现在觉得,慢一点会更快。学习贵在持之以恒,我觉得我可以一天刷十道题、二十道题,但是我没有可能这样坚持下去。每天一道就挺好,仔细研究细节、不会厌倦,将目光放到一年后、两年后,得到的积累与进步也将是十分可观了。...原创 2021-10-18 15:50:04 · 64 阅读 · 0 评论 -
LeetCode刷题日记(2. 两数相加)
2.两数相加答题思路:使用两个指针对输入的链表进行遍历,每次遍历后将结果保存在数组中,最后将数组中的值传入新建链表中。/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2原创 2021-10-18 15:32:09 · 160 阅读 · 0 评论