LeetCode
Mr_wwb123
做喜欢的事,顺便挣点钱//一起交流学习
展开
-
【一天一道】leetcode Sort a linked list in O(n log n) time using constant space complexity.
据说要用归并方法,分而治之: head :左边 mid:右边 将链表分为两部分,左边和右边,先找到中间节点,对左边和右边有序数列进行排序,将最新的链表 2 1 || 0 4 / \ ...原创 2019-06-18 23:30:22 · 92 阅读 · 0 评论 -
【一天一道】八皇后的递归与非递归
递归: public class eightQueue { static int record[] = new int[8]; static int num = 0; static int N = 8; public static void main(String []args){ System.out.println("start*******...原创 2019-06-14 12:55:32 · 272 阅读 · 0 评论 -
【一天一道】Sort a linked list using insertion sort.
插入排序 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } ...原创 2019-06-19 22:56:30 · 106 阅读 · 0 评论 -
【一天一道】Given a binary tree, return the postorder traversal of its node
For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[3,2,1]. Note:Recursive solution is trivial, could you do it iteratively? 二叉树遍历方式:前序,后序,中序 后序:先左右后根——[3, 2, 1] ...原创 2019-06-21 00:30:12 · 143 阅读 · 0 评论 -
【一天一道】You must do this in-place without altering the nodes' values
Given a singly linked listL:L0→L1→…→Ln-1→Ln, reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example, Given{1,2,3,4}, reord...原创 2019-06-21 21:44:13 · 121 阅读 · 0 评论 -
【一天一道】统计在从1到n的正整数中指定字符的次数
package leetCode; //ch='0'的场景还没看;要进行区分下 /* 给定一个十进制正整数N,写下从1开始,到N的所有整数,然后数一下其中出现的所有“1”的个数。 以20310为例,计算百位出现1的次数,将其分为a=203,b = 10,百位的高位为20,低位为10 1、当百位数字小于1时,高位取值0-19,即高位*100 2、当百位数字等于1时,高位取值0-19,即高位*1...原创 2019-06-25 01:18:54 · 463 阅读 · 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? 解题思路:快慢指针,从起点走,快指针步长为2,慢指针步长为1,假设有环,相遇时,快指针走了...原创 2019-06-28 00:33:56 · 295 阅读 · 2 评论