
LeetCode
ou.cs
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 371 两整数之和(不使用+、-运算符)
#include "stdio.h"int getSum(int a, int b) { int sum; unsigned int carry; while (1) { sum = a ^ b; //1.第一次为没有进位的值 2.后面相或补进位 carry = a & b; //需要进位对应的值 if (carry == 0) //直到没有要进的位 { break; } a = sum; b = carry << 1; //每进一原创 2021-09-26 11:32:45 · 167 阅读 · 0 评论 -
LeetCode 204 反转链表
#include "stdio.h"#include <corecrt_malloc.h>struct ListNode { int val; struct ListNode *next;};struct ListNode* reverseList(struct ListNode* head);struct ListNode** addNode(struct ListNode** l1, int val){ *l1 = (struct ListNo..原创 2021-09-24 17:35:04 · 183 阅读 · 0 评论 -
LeetCode 3 无重复字符的整个子串
[left,i]之间是否可能会有重复字符?不会。以 abccba为例,首先上一个相同字符出现位置需大于左边界,才会更新左边界,若左边界未更新,则为上一次最近的相同字符出现的位置因此,若有重复字符,则早就判断了。所以不会存在重复的。#include "stdio.h"#include "math.h"#include "string.h"int lengthOfLongestSubstring(char* s);int main(){ printf("%d" , lengt.原创 2021-09-24 14:15:16 · 192 阅读 · 0 评论 -
LeetCode 2 两数之和
分三种情况:链表1比链表2长链表2比链表1长最后一位进位易错点分析:判断链表结束位置应为当前节点是否为空,(头)节点初始化时应为空,申请空间时应用到才申请。struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){ struct ListNode* l3 = NULL; struct ListNode* head =NULL; int bit = 0; while (l1 || l2..原创 2021-09-23 09:51:54 · 199 阅读 · 0 评论 -
LeetCode 204 线性筛 计数质数
static public int CountPrimes(int n) { //buf 存放所有数据,默认全部为素数 bool[] buf = new bool[n]; //primeBuf 存放素数,这是有序的,从小到大。 int[] primeBuf = new int[n]; //标记已存放多少个素数 int primeSize = 0;原创 2020-12-03 17:36:51 · 229 阅读 · 0 评论