随笔分类 -  leecode

刷算法,求好运
摘要:#include <stdio.h> //数组当中只出现一次的那个数 int getSingle(int* arr,int len){ int single = 0,i; if(len == 1) return *arr; for(i=0;i<len;i++) single ^= arr[i]; r 阅读全文
posted @ 2020-04-03 12:15 bug_killer 阅读(181) 评论(0) 推荐(0)
摘要:#include "head.h" int* mergeTwoSeqArr(int* a,int la,int* b,int lb){ int i = 0,j=0; int *stack = (int*)malloc(sizeof(int)*(la+lb)); int top = 0; while(i<la&&j<lb){ if(a[i]<=b[j]){ stack[top++] = a[i++] 阅读全文
posted @ 2019-09-26 16:51 bug_killer 阅读(200) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { pub... 阅读全文
posted @ 2019-07-11 16:51 bug_killer 阅读(729) 评论(0) 推荐(0)
摘要:public ListNode reverseBetween(ListNode head, int m, int n) { ListNode dummy = new ListNode(0); //虚拟头结点往往是有必要的,好处非常明显 dummy.next = head; ListNode pre = dummy; for(in... 阅读全文
posted @ 2019-05-03 11:22 bug_killer 阅读(824) 评论(0) 推荐(0)
摘要:编写一个算法来判断一个数是不是“快乐数”。 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1。如果可以变为 1,那么这个数就是快乐数。 示例: 输入: 19 输出: true 解释: 1^2 + 9^2 = 82 8^2 + 2^2 = 68 6^2 + 8^2 = 100 1^2 ... 阅读全文
posted @ 2019-05-03 11:05 bug_killer 阅读(178) 评论(0) 推荐(0)
摘要://字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。 //请找出在 t 中被添加的字母 阅读全文
posted @ 2019-04-17 14:29 bug_killer 阅读(120) 评论(0) 推荐(0)
摘要:struct ListNode* oddEvenList(struct ListNode* head) { if(head==NULL || head->next==NULL) return head; struct ListNode *odd = head; struct ListNode *even = head->next,*even_head = even; ... 阅读全文
posted @ 2019-04-16 13:13 bug_killer 阅读(128) 评论(0) 推荐(0)
摘要:void InsertSort(struct ListNode* L){ struct ListNode *p = L->next,*pre=NULL; struct ListNode *r = p->next; p->next = NULL; p = r; while(p!=NULL){ r = p->next; pre ... 阅读全文
posted @ 2019-04-16 12:24 bug_killer 阅读(305) 评论(0) 推荐(0)
摘要://设计一个找到数据流中第K大元素的类(class)。 //注意是排序后的第K大元素,不是第K个不同的元素。 class KthLargest { private PriorityQueue queue; private int k = 0; public KthLargest(int k, int[] nums) { queue = new Prior... 阅读全文
posted @ 2019-04-15 08:25 bug_killer 阅读(278) 评论(0) 推荐(0)
摘要://采用不带头结点的链表 非递归实现 public static ListNode merge(ListNode list1,ListNode list2){ if(list1==null) return list2; else if(list2==null) return list1; ListNode newHead=null; ListNode tmp=null; ... 阅读全文
posted @ 2019-04-12 14:32 bug_killer 阅读(1064) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2019-04-10 17:59 bug_killer 阅读(173) 评论(0) 推荐(0)
摘要:#include #include //计算1000!尾数零的个数 //扩展n!的尾数零的个数 //2^a * 5^b //obviously a>b //so count = b //5*1 5*2 .....5*200 200个 除以5 //1 2 3 4 5 .... 200 中 包含 5*(1,2,3,4,...40) 40个 除以5 //5*1 5*2 ..... 5*8 v... 阅读全文
posted @ 2019-03-23 15:42 bug_killer 阅读(155) 评论(0) 推荐(0)
摘要:char* intToRoman(int num) { if(num3999) return; char *r = (char*)malloc(sizeof(char)*20); char* I[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; char* X[10] = {"... 阅读全文
posted @ 2019-03-23 15:41 bug_killer 阅读(191) 评论(0) 推荐(0)
摘要:int max(int a,int b) { return a>=b?a:b;} int min(int a,int b) { return a>=b?b:a;} int maxArea(int* height, int heightSize) { int i = 0; int j = heightSize-1; int area = 0; int dist =... 阅读全文
posted @ 2019-03-23 15:07 bug_killer 阅读(104) 评论(0) 推荐(0)