给定一个正整数 n,你可以做如下操作: \1. 如果 n 是偶数,则用 n / 2替换 n。 \2. 如果 n 是奇数,则可以用 n + 1或n - 1替换 n。 n 变为 1 所需的最小替换次数是多少? 示例 1: 输…
分类:LeetCode
[LeetCode By Go 4]476. Number Complement
题目描述 Given a positive integer, output its complement number. The complement strategy is to flip the bits of it…
[LeetCode] Reverse Bits 翻转位, Grey Code
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in bin…
[LeetCode] Design Tic-Tac-Toe 设计井字棋游戏
Design a Tic-tac-toe game that is played between two players on a n x n grid. You may assume the follow…
[LeetCode] Encode String with Shortest Length 最短长度编码字符串
Given a non-empty string, encode the string such that its encoded length is the shortest. The encoding …
LeetCode | Minimum Path Sum(最小路径和)
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom r…
Leetcode PHP题解--D32 617. Merge Two Binary Trees
617. Merge Two Binary Trees 题目链接 617. Merge Two Binary Trees 题目分析 给定两个二叉树,返回一个 将对应位置值相加后的二叉树。 例如,树A的顶点值为1,树B的顶…
123. 买卖股票的最佳时机 III
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if len(prices…
[LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
A sequence of numbers is called arithmetic if it consists of at least three elements and if the differe…
[Leetcode] Next Permutation 下一个排列
Next Permutation Implement next permutation, which rearranges numbers into the lexicographically next greater …
[Leetcode] Delete Node/Remove Element in a Linked List 删除链表节点
Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly linked list, give…
【Leetcode】13. Roman to Integer 罗马数字转阿拉伯数字
1. 题目 Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 39…