随笔分类 - Leetcode
摘要:1. 题目 https://leetcode.com/problems/binary-tree-inorder-traversal/ #2. 分析 2.1 迭代法 class Solution { public: vector<int> inorderTraversal(TreeNode* root
阅读全文
摘要:1. 题目 https://leetcode.com/problems/factorial-trailing-zeroes/ #2. 分析 这一题需要我们观察一下规律,可以发现, 阶乘后的0元素是有2和5组成的,这里的2和5也包括他们的倍数,例如2的倍数4,6,8...,而5的倍数包括5,10,15
阅读全文
摘要:1. 题目 https://leetcode.com/problems/climbing-stairs/ #2. 分析 以下三种算法的详细介绍参考:https://yyqx.online/posts/leetcode70climbing-stairs/ ##2.1 自顶向下的递归暴力求解法 具体代码
阅读全文
摘要:1. 题目 https://leetcode.com/problems/sqrtx/ #2. 分析 ##2.1 牛顿迭代法 牛顿迭代法是一种求解非线性方程的一种数值方法。具体原理可以参考:https://blog.csdn.net/u014485485/article/details/7759995
阅读全文
摘要:1. 题目 https://leetcode.com/problems/palindrome-number/ #2. 分析 这一题可以将数字直接反转,如果反转后数字和原数字相同,则一定是回文数。当然对于负数可以直接返回false 具体代码如下: class Solution { public: bo
阅读全文
摘要:1. 题目 https://leetcode.com/problems/reverse-integer/ #2. 分析 这一题整数反转,题目不难,需要注意的是32位数字和数字前面几位不能为0,关于32位数字,建议中间存储结果时不要使用int,而是使用类似于int64_t的范围更广的类型。 具体代码如
阅读全文
摘要:1. 题目 https://leetcode.com/problems/intersection-of-two-linked-lists/ #2. 分析 我们可以将列表A和B分别分为三部分,分别为AB公共部分,交点和非公共部分,也就是 A = A非公共部分 + 交点 + AB公共部分 B = B非公
阅读全文
摘要:1. 题目 1.1 英文题目 Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted a
阅读全文
摘要:1. 题目 1.1 英文题目 Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted a
阅读全文
摘要:1. 题目 1.1 英文题目 Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two l
阅读全文
摘要:1. 题目 1.1 英文题目 Given a string columnTitle that represents the column title as appear in an Excel sheet, return its corresponding column number. 1.2 中文
阅读全文
摘要:1. 题目 1.1 英文题目 Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. 1.2 中文题目 给定一个正整数,返回它在 Excel 表中相对应
阅读全文
摘要:1. 题目 1.1 英文题目 Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 1.2 中文题目 给定一个字符串,验证它是否是
阅读全文
摘要:1. 题目 1.1 英文题目 Given two binary strings a and b, return their sum as a binary string. 1.2 中文题目 给定两个二进制字符串,返回他们的和(用二进制表示)。输入为非空字符串且只包含数字 1 和 0。 1.3输入输出
阅读全文
摘要:1. 题目 1.1 英文题目 Given a string s consists of some words separated by spaces, return the length of the last word in the string. If the last word does no
阅读全文
摘要:1. 题目 1.1 英文题目 Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Clarificat
阅读全文
摘要:1. 题目 1.1 英文题目 Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input strin
阅读全文
摘要:1. 题目 1.1 英文题目 Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty st
阅读全文
摘要:1. 题目 1.1 英文题目 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. | Symbol | Value | | | | | I | 1 | | V | 5 | | X | 1
阅读全文
摘要:1. 题目 1.1 英文题目 Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. Y
阅读全文