摘要: 编写一个算法来判断一个数是不是“快乐数”。 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 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 阅读(176) 评论(0) 推荐(0)
摘要: #include //char类型数据范围 [-128,127] // ......-132 -131 -130 -129 -128 .. 127 128 129 130 131 132.... // ...... 124 125 126 127 -128 .. 127 -128 -127 -126 -125 -124.... int main() { char t1... 阅读全文
posted @ 2019-04-28 10:05 bug_killer 阅读(932) 评论(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)
摘要: package common; import java.util.ArrayList; import java.util.BitSet; import java.util.List; import java.util.Random; public class BitMapDemo { /** * 有1千万个随机数,随机数的范围在1到1亿之间。现在要求写出一种算法,将1到1亿之间没有在随... 阅读全文
posted @ 2019-04-11 11:08 bug_killer 阅读(577) 评论(0) 推荐(0)
摘要: package problem.回溯; public class EightQueue { public static int max = 8,sum = 0; public static int[] queen = new int[max]; //存储列元素值 //皇后元素形式:(i,queue[i]) public void displayQue... 阅读全文
posted @ 2019-04-11 10:30 bug_killer 阅读(261) 评论(0) 推荐(0)
摘要: package 排序; import common.Utils; public class HeapSort { public static void Adjust(int[] arr,int startIndex,int len){ int childIndex = 0; int threshold = len-1; for(;2*... 阅读全文
posted @ 2019-04-11 10:28 bug_killer 阅读(362) 评论(0) 推荐(0)