LeetCode刷题经历
whl_program
这个作者很懒,什么都没留下…
展开
-
[LeetCode]404. 左叶子之和
原题链接:https://leetcode-cn.com/problems/sum-of-left-leaves/思路:递归,dfs左叶子节点:是父亲节点的左孩子,左节点和右节点都是null代码/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} *原创 2021-09-08 13:49:08 · 127 阅读 · 0 评论 -
[LeetCode]784. 字母大小写全排列
原题链接https://leetcode-cn.com/problems/letter-case-permutation/submissions/思路:类似于字符串全排列,只是不需要变换位置,改成了转换大小写代码class Solution { public List<String> letterCasePermutation(String s) { List<String> result = new ArrayList<>();原创 2021-09-08 22:45:12 · 162 阅读 · 0 评论 -
[LeetCode]202. Happy Number(判断正整数是不是Happy Number)
202. Happy Number原题链接 Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the原创 2017-06-03 01:28:38 · 1861 阅读 · 3 评论 -
[LeetCode]12. Integer to Roman(整数转化为罗马数字)
12. Integer to Roman点击查看相关题 罗马数字转化为整数 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.题目大意: 给定一个整数,将其转换为罗马数字。 输入保证在1到3999之间。首先明确组合规则: (1)原创 2017-04-27 00:49:35 · 621 阅读 · 0 评论 -
[LeetCode]217. Contains Duplicate(判断数组中是否有重复元素)
217. Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return fal原创 2017-04-26 20:29:22 · 862 阅读 · 0 评论 -
[LeetCode]447. Number of Boomerangs(求回旋镖数量)
447. Number of Boomerangs原题链接 Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance betwee原创 2017-05-09 00:01:02 · 1293 阅读 · 0 评论 -
[LeetCode]563. Binary Tree Tilt(二叉树的差值)
563. Binary Tree TiltGiven a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of原创 2017-04-25 20:25:17 · 3361 阅读 · 0 评论 -
[LeetCode]575. Distribute Candies(妹妹最多能得到多少种糖果)
575. Distribute Candies原题链接 Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind.原创 2017-05-07 20:28:36 · 3975 阅读 · 0 评论 -
[LeetCode]344. Reverse String(反转字符串)
344. Reverse StringWrite a function that takes a string as input and returns the string reversed. 题目大意:反向输出字符串Example:Given s = "hello", return "olleh".代码如下C++class Solution {public: string reve原创 2017-03-01 00:52:37 · 716 阅读 · 0 评论 -
[LeetCode]461. Hamming Distance(汉明距离)
LeetCode 461. Hamming Distance题目描述: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 Hamm...原创 2017-02-21 00:38:18 · 369 阅读 · 0 评论 -
[LeetCode]476. Number Complement(数字补码)
476. Number Complement题目描述:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. 给定一个正整数,输出其补数。 补码策略是翻转其二进制表示的位。Note:(数据范围)原创 2017-02-22 00:49:26 · 569 阅读 · 0 评论 -
[LeetCode]500. Keyboard Row(输出在键盘一行上能敲出来的单词)
500. Keyboard RowGiven a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below. 给定一个单词列表,返回可以只在美国键盘的一行上输入的单词(使用字母表中的字母原创 2017-02-23 00:45:58 · 532 阅读 · 0 评论 -
[LeetCode]496. Next Greater Element I(下一个更大的元素 1)
496. Next Greater Element IYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corres原创 2017-02-28 01:10:09 · 872 阅读 · 0 评论 -
[LeetCode]463. Island Perimeter(岛周长)
463. Island PerimeterYou are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The原创 2017-03-01 01:05:18 · 421 阅读 · 0 评论 -
[LeetCode]485. Max Consecutive Ones(最大连续为1的数量)
485. Max Consecutive OnesGiven a binary array, find the maximum number of consecutive 1s in this array. 题目大意:给一个二进制数组,找到连续为1的最大数量Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two di原创 2017-03-01 01:51:19 · 509 阅读 · 0 评论 -
[LeetCode]292. Nim Game(轮流拿掉石头)
292. Nim GameYou are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone原创 2017-03-08 09:18:39 · 914 阅读 · 0 评论 -
[LeetCode]520. Detect Capital(检测单词是否合法)
520. Detect CapitalGiven a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: -原创 2017-03-08 10:29:01 · 594 阅读 · 0 评论 -
[LeetCode]13. Roman to Integer(罗马数字转化为整数)
13. Roman to Integer点击查看相关题 整数转化为罗马数字 Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.题目大意: 给定一个罗马数字,将其转换为整数。 输入保证在1到3999之间。罗马数字定义:罗马数字共有原创 2017-04-27 00:18:41 · 1560 阅读 · 1 评论 -
[LeetCode]268. Missing Number(求数组中缺失的元素)
268. Missing Number原题链接 Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. 给定一个包含从0,1,2,…,n中取出的n个不同数字的数组,找到数组中缺少的元素。 For exampleGiven原创 2017-05-10 11:41:14 · 490 阅读 · 0 评论 -
[LeetCode]437. Path Sum III(求二叉树中路径和等于sum的数量)
437. Path Sum III原题链接 相似题目题解:112. Path Sum && 113. Path Sum IIYou are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does原创 2017-07-24 20:21:46 · 786 阅读 · 0 评论 -
[LeetCode]113. Path Sum II(列出二叉树根到叶路径和等于sum的所有路径)
113. Path Sum II原题链接 相似题目题解:112. Path Sum && 437. Path Sum III Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.For example: Given the below binar原创 2017-07-21 18:53:02 · 834 阅读 · 1 评论 -
[LeetCode]112. Path Sum(判断二叉树根到叶路径和是否等于sum)
112. Path Sum原题链接 相似题目题解:113. Path Sum II && 437. Path Sum III Given 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 equa原创 2017-07-19 19:35:37 · 693 阅读 · 0 评论 -
[LeetCode]70. Climbing Stairs(求爬楼梯有几种方式)
70. Climbing Stairs原题链接 You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?原题大意:给一个台阶数原创 2017-06-12 16:12:43 · 587 阅读 · 0 评论 -
[LeetCode]83. Remove Duplicates from Sorted List(删除有序链表的重复元素 )
83. Remove Duplicates from Sorted List原题链接 Given a sorted linked list, delete all duplicates such that each element appear only once. 给一个链表,删除重复元素 For example,Given 1->1->2, return 1->2.Given 1->1-原创 2017-06-10 00:44:29 · 400 阅读 · 0 评论 -
[LeetCode] 231. Power of Two(判断整数是否是2的幂)
231. Power of Two原题链接参考相似题326. Power of ThreeGiven an integer, write a function to determine if it is a power of two.给一个整数,写一个函数判断是否是2的幂。思路:判断是否<=0 或者>2147483647,是的话返回false判断n%2 == 0,是的话n /= 2,循环进行,一原创 2017-06-09 23:39:02 · 496 阅读 · 0 评论 -
[LeetCode]326. Power of Three(判断整数是否是3的幂)
326. Power of Three原题链接参考相似题 [LeetCode] 231. Power of TwoGiven an integer, write a function to determine if it is a power of three. 给一个整数,写一个函数判断其是否是3的幂Follow up:Could you do it without using any loop原创 2017-06-09 23:17:10 · 492 阅读 · 0 评论 -
[LeetCode]121. Best Time to Buy and Sell Stock(求近期股票能获得的最大利润)
121. Best Time to Buy and Sell Stock原题链接 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, bu原创 2017-06-03 00:07:34 · 438 阅读 · 0 评论 -
[LeetCode]405. Convert a Number to Hexadecimal(32位有符号整数转化为十六进制)
405. Convert a Number to Hexadecimal原题链接 Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. 题目大意: 给一个整数,写出它的十六进制,对于负整数,可以用二进制补码原创 2017-05-31 00:11:47 · 1973 阅读 · 0 评论 -
[LeetCode]415. Add Strings(计算两个字符串表示的数字的和)
415. Add Strings原题链接 Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. 给定两个用字符串表示的非负整数num1和num2,返回用字符串表示的num1和num2的和。Note:The length of both num1原创 2017-05-29 21:43:38 · 2880 阅读 · 0 评论 -
[LeetCode]108. Convert Sorted Array to Binary Search Tree(升序数组转化为平衡二叉树)
108. Convert Sorted Array to Binary Search Tree原题链接 Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题目大意: 给定一个升序数组,转化为一个平衡二叉树思路:首先要了解二叉排序树BST的定义。给定一个原创 2017-05-29 17:32:00 · 604 阅读 · 0 评论 -
[LeetCode]572. Subtree of Another Tree(判断树t是否是树S的子树)
572. Subtree of Another Tree原题链接 Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of原创 2017-05-28 00:21:38 · 1101 阅读 · 0 评论 -
[LeetCode]543. Diameter of Binary Tree(计算二叉树的直径的长度)
543. Diameter of Binary Tree原题链接 Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes原创 2017-05-27 23:10:39 · 675 阅读 · 0 评论 -
[LeetCode]541. Reverse String II(间隔反转字符串)
541. Reverse String II原题链接 Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k character原创 2017-05-23 21:12:49 · 982 阅读 · 0 评论 -
[LeetCode]136. Single Number(找出数组中单独出现的数)
136. Single NumberGiven an array of integers, every element appears twice except for one. Find that single one. 题目大意:给定一个整数数组,每个元素出现两次,只要一个元素出现一次。 找到这个元素。 Note: Your algorithm should have a linear r原创 2017-03-08 13:00:28 · 360 阅读 · 0 评论 -
[LeetCode]448. Find All Numbers Disappeared in an Array(查找数组中消失的所有数字)
448. Find All Numbers Disappeared in an ArrayGiven an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclu原创 2017-03-08 21:03:22 · 449 阅读 · 0 评论 -
[LeetCode]104. Maximum Depth of Binary Tree(二叉树最大深度)
104. Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 题目大意: 给原创 2017-03-08 23:48:06 · 345 阅读 · 0 评论 -
[LeetCode]168. Excel Sheet Column Title(Excel表格列标题)
168. Excel Sheet Column Title和171题是一个类型的,参考[LeetCode]171. Excel Sheet Column NumberGiven a positive integer, return its corresponding column title as appear in an Excel sheet. 给定一个正整数,返回相应的列标题,如Excel表原创 2017-04-18 00:51:27 · 443 阅读 · 0 评论 -
[LeetCode]171. Excel Sheet Column Number(Excel表格列号)
171. Excel Sheet Column Number和168题是一个类型的,参考[LeetCode]168. Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number. 给出Excel表格中显示的列标题,返回其对应的列号。F原创 2017-04-18 00:56:24 · 382 阅读 · 0 评论 -
[LeetCode]237. Delete Node in a Linked List(删除链表结点)
237. Delete Node in a Linked ListWrite a function to delete a node (except the tail) in a singly linked list, given only access to that node. 编写一个函数来删除单链表中的节点(尾部除外),只允许访问该节点。Supposed the linked list i原创 2017-04-19 23:52:01 · 376 阅读 · 0 评论 -
[LeetCode]100. Same Tree(相同树)
100. Same TreeGiven two binary trees, write a function to check if they are equal or not. 给定两个二叉树,写一个函数来检查它们是否相等。Two binary trees are considered equal if they are structurally identical and the nodes原创 2017-04-20 00:34:36 · 2230 阅读 · 0 评论