
LeetCode
文章平均质量分 52
小萝莉_Lolita
做自己的superman
展开
-
剑指Offer面试题10:二进制中1的个数
题目描述:请实现一个函数,输入一个整数,输入该数二进制表示中1的个数。 例如:把9表示成二进制是1001,有2位是1,所以输入9,该函数输出2 可能引起死循环的解法思路:先判断整数二进制数的最后一位是不是1,然后整数右移一位,此时原来处于倒数第二位就被移到最右边了,再判断是否是1。也就是,依次右移,如果最后一位是1,则得到1,如果是0,则得到0 这种思路中,待判断的整数右移,而辅...原创 2018-03-08 11:37:43 · 229 阅读 · 0 评论 -
【leetcode】中关于二叉树的那些题
112 Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note: A leaf is a node with no...原创 2018-04-28 19:27:38 · 411 阅读 · 0 评论 -
【LeetCode】SingleNumber[I][II]
题目描述Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without ...原创 2018-04-25 17:07:02 · 249 阅读 · 0 评论 -
LeetCode Word Break解题报告
题目描述Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s =”leetcode”, dict =[...原创 2018-04-25 16:10:34 · 1470 阅读 · 0 评论 -
Given a linked list, return the node where the cycle begins.
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up: Can you solve it without using extra space? 给定一个链表,判断是否有环,如果没有环,直接返回null。(解决这个问题而不需要额外的空间) ...原创 2018-04-25 10:09:35 · 663 阅读 · 0 评论 -
Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…
题目描述Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You must do this in-place without altering the nodes’ values.(在不改变结点值的情况下) For example, G...原创 2018-04-25 09:52:59 · 1286 阅读 · 0 评论 -
Given a binary tree, return the postorder traversal of its nodes' values.非递归后续遍历
Given a binary tree, return the postorder traversal of its nodes’ values. For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1]. Note: Recursive solutio...原创 2018-04-24 23:20:47 · 538 阅读 · 0 评论 -
Sort a linked list using insertion sort.
题录:Sort a linked list using insertion sort. 分析如下:使用插入排序的方法,对一个链表进行排序。 插入排序的思想:第i个元素插入到已排序的前i-1个元素中。 注意 1 排好序的新链表和旧链表要断开。 2 什么叫做插入排序,从A[1]到A[n],依次把旧链表中的旧元素放入新链表的正确位置中,新链表是从没有元素开始逐渐排好序的...原创 2018-04-23 23:52:35 · 294 阅读 · 0 评论 -
Sort a linked list in O(n log n) time using constant space complexity.
Sort a linked list in O(n log n) time using constant space complexity. Example 1:Input: 4->2->1->3 Output: 1->2->3->4 Example 2:Input: -1->5->3->4->0 Outp...原创 2018-04-23 23:01:06 · 194 阅读 · 0 评论 -
二叉排序树的操作
删除结点是比较麻烦的,这里简要介绍一下如何删除结点 1.待删除的结点是叶子结点,这种很简单,直接令指向该结点的指针指向null即可 2.待删除的结点只有左子树,这种也比较好操作,令指向该结点的指针指向该结点的左子树即可 3.待删除的结点只有右子树,这种同上操作,令指向该结点的指针指向该结点的右子树即可 4.待删除的结点的左子树和右子树均不为空,这种情况下,我们可以将删除操作进行转换,转换为...原创 2018-03-13 15:21:48 · 407 阅读 · 0 评论 -
leetCode155. Min Stack
题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() ...原创 2018-03-05 17:49:42 · 269 阅读 · 0 评论 -
剑指Offer面试题28:字符串的排列之相关题目
1.输入一个含有8个数字的数组,判断有没有可能把这8个数字分别放到正方体的8个顶点上,使得正方体三组相对的面上的4个顶点的和都相等 其实这道题跟字符串的排列是一样的,相当于先得到a1,a2,a3,a4,a5,a6,a7,a8这8个数字的所有排列,然后判断有没有某一个排列符合题目给定的条件,即 a1 + a2 + a3 + a4 == a5 + a6 + a7 + a8 a1 + a3 +...原创 2018-03-12 20:40:34 · 327 阅读 · 0 评论 -
剑指Offer面试题28及其扩展:求字符的所有组合
题目描述:如果不是求字符的所有排列,而是求字符的所有组合。比如,输入三个字符a,b,c,则它们的组合有a,b,c,ab,ac,bc,abc。当交换字符串中的两个字符时,虽然能得到两个不同的排列,但却是同一个组合,比如ab和ba是不同的排列,但只算一个组合 思路分析:如果输入n个字符,则这n个字符能构成长度为1的组合,长度为2的组合,……..,长度为n的组合。在求n个字符长...原创 2018-03-12 16:24:27 · 901 阅读 · 0 评论 -
剑指Offer面试题27:二叉搜索树与双向链表
题目描述:输入一课二叉搜索树,将该二叉树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。比如,输入图中的二叉搜索树,则输出转换之后的双向链表 从中我们可以发现双向链表中的结点顺序和二叉搜索树的中序遍历得到的序列顺序是一样的。 我们可以使用递归和非递归两种方式实现这道题的求解 非递归方式:我们借助栈结构,同时我们需要记录当前结点和前一个结点,这样我们就...原创 2018-03-12 14:24:26 · 292 阅读 · 0 评论 -
leetCode138.Copy List with Random Pointer
题目描述: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 大意:给定一个链表,每个节点包含一个random指...原创 2018-03-02 14:53:57 · 237 阅读 · 0 评论 -
461. Hamming Distance
Description:The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance No...原创 2018-02-19 18:09:48 · 237 阅读 · 0 评论 -
771. Jewels and Stones
Description:You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know h...原创 2018-02-19 16:39:16 · 354 阅读 · 0 评论 -
【LeetCode】Two Sum问题
1.Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may no...原创 2018-04-28 20:33:29 · 241 阅读 · 0 评论