我的代码游记

标签 · Medium

首页

关于

归档

计数LeetCodeMedium数组

80.Remove Duplicates from Sorted Array II(Medium)

Follow up for “Remove Duplicates”:What if duplicates are allowed at most twice?给定一个有序的整数数列,每个数最多只能出现两次,然后去除多余的数,把剩下的数排在原数组的前面,并返回新数列的长度 *  这虽然是个中等题,不过难度不大,唯一需要多考虑的就是在原数组前面排列新的数组* For example Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn’t matter what ..

更多
loading..
LeetCodeMediumDFS

264.Ugly Number II(Medium)

Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note that 1 is typically treated as an ugly number. *  题意就不翻译了,意思就是把丑数从小到大排列,输出制定位置的那个丑数是多少,按照上一题的那种朴素判断当然是行得通的,只要把1~n的数全部都验证一遍,自然可以找到第n个,但..

更多
LeetCodeMedium链表

328.Odd Even Linked List(Medium)

Given a singly linked list, group all odd nodes together followed by the even nodes.Please note here we are talking about the node number and not the value in the nodes.You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity. *  题目不难理解我就不翻译了,就是一个单链表,把所有奇数的结点放在前面,然后接着所有的偶数结点,然后要求在时间复杂度O(n)和空间复杂度O(1)之下..

更多
计数LeetCodeMedium递归二叉树

222.Count Complete Tree Nodes(Medium)

Given a complete binary tree, count the number of nodes.给定一个完全二叉树,计算其节点数 **Definition of a complete binary tree from Wikipedia:**In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h. *  难度在于其如何优..

更多
12