leetcode
文章平均质量分 65
dinglin0xff
世事一场大梦 人生几度秋凉 gitee: https://gitee com/d1nglin
展开
-
LeetCode 514. 自由之路
514.自由之路目录思路代码复杂度分析思路构建一个映射表,记录ring中每个下标向前向后到达每个字母的距离。然后BFS枚举,只枚举当前位置向前向后的到达目标字符,并记录。枚举的时候采用了一些小优化,map的重复使用,以及只记录需要遍历的pos等等。代码func findRotateSteps(ring string, key string) int { ...原创 2019-06-04 15:59:19 · 264 阅读 · 0 评论 -
LeetCode-Excel Sheet Column Title-解题报告
原题链接https://leetcode.com/problems/excel-sheet-column-title/Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -原创 2015-07-03 17:59:23 · 327 阅读 · 0 评论 -
LeetCode-Excel Sheet Column Number-解题报告
原题链接https://leetcode.com/problems/excel-sheet-column-number/Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number原创 2015-07-03 18:31:29 · 302 阅读 · 0 评论 -
LeetCode-Factorial Trailing Zeroes-解题报告
原题链接https://leetcode.com/problems/factorial-trailing-zeroes/Given an integer n, return the number of trailing zeroes inn!.Note: Your solution should be in logarithmic time complexity.求n!的尾部有原创 2015-07-03 16:56:11 · 252 阅读 · 0 评论 -
LeetCode-Binary Search Tree Iterator-解题报告
原题链接https://leetcode.com/problems/binary-search-tree-iterator/Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next()原创 2015-07-03 15:43:19 · 339 阅读 · 0 评论 -
LeetCode-Word Search II-解题报告
原题链接https://leetcode.com/problems/word-search-ii/Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequent转载 2015-07-02 14:30:20 · 385 阅读 · 0 评论 -
LeetCode-Shortest Palindrome-解题报告
原题链接:https://leetcode.com/problems/shortest-palindrome/Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindr原创 2015-07-02 14:02:19 · 443 阅读 · 0 评论 -
LeetCode-Repeated DNA Sequences -解题报告
原题链接https://leetcode.com/problems/repeated-dna-sequences/All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes原创 2015-07-02 16:48:38 · 237 阅读 · 0 评论 -
LeetCode-Best Time to Buy and Sell Stock III -解题报告
原题链接https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maxi原创 2015-07-02 12:33:08 · 367 阅读 · 0 评论 -
LeetCode-Add and Search Word - Data structure design-前缀树
原题链接https://leetcode.com/problems/add-and-search-word-data-structure-design/Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(wor原创 2015-07-02 14:37:50 · 442 阅读 · 0 评论 -
LeetCode-Kth Smallest Element in a BST-解题报告
原题链接https://leetcode.com/problems/kth-smallest-element-in-a-bst/Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always原创 2015-07-02 13:57:11 · 423 阅读 · 0 评论 -
LeetCode-Largest Number-解题报告
原题链接https://leetcode.com/problems/largest-number/Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest form原创 2015-07-02 19:35:42 · 298 阅读 · 0 评论 -
LeetCode-House Robber-解题报告
原题链接https://leetcode.com/problems/house-robber/You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping y原创 2015-07-02 14:21:37 · 325 阅读 · 0 评论 -
LeetCode-Best Time to Buy and Sell Stock IV -解题报告
原题链接https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maxim原创 2015-07-02 13:23:48 · 261 阅读 · 0 评论 -
LeetCode-Binary Tree Level Order Traversal-解题报告
原题链接 https://leetcode.com/problems/binary-tree-level-order-traversal/Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For exam原创 2015-07-08 19:34:16 · 222 阅读 · 0 评论 -
LeetCode-Number of 1 Bits-解题报告
原题链接 https://leetcode.com/problems/number-of-1-bits/Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the原创 2015-07-08 19:19:58 · 395 阅读 · 0 评论 -
LeetCode-Majority Element -解题报告
原题链接https://leetcode.com/problems/majority-element/Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume th原创 2015-07-03 18:42:30 · 435 阅读 · 0 评论 -
LeetCode-Reverse Integer-解题报告
原题链接 https://leetcode.com/problems/reverse-integer/Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321 class Solution {public: int reverse(int x) {原创 2015-07-08 21:26:43 · 262 阅读 · 0 评论 -
LeetCode-Integer to English Words-解题报告
原题链接 https://leetcode.com/problems/integer-to-english-words/Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,原创 2015-09-02 11:51:31 · 531 阅读 · 0 评论 -
LeetCode-Add Digits-解题报告
原题链接 https://leetcode.com/problems/add-digits/Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the proces原创 2015-08-29 18:58:02 · 299 阅读 · 0 评论 -
LeetCode-Binary Tree Paths -解题报告
原题链接 https://leetcode.com/problems/binary-tree-paths/Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5原创 2015-08-29 23:55:29 · 252 阅读 · 0 评论 -
LeetCode-Lowest Common Ancestor of a Binary Search Tree-解题报告
原题链接 https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Accordin原创 2015-07-20 17:43:17 · 312 阅读 · 0 评论 -
LeetCode-Ugly Number II-解题报告
原链接https://leetcode.com/problems/ugly-number-ii/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,原创 2015-08-28 15:52:15 · 289 阅读 · 0 评论 -
LeetCode-Missing Number-解题报告
原题链接 https://leetcode.com/problems/missing-number/Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given n原创 2015-08-27 16:16:05 · 342 阅读 · 0 评论 -
LeetCode-Ugly Number-解题报告
原链接 https://leetcode.com/problems/ugly-number/Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.原创 2015-08-28 16:41:49 · 286 阅读 · 0 评论 -
LeetCode-Single Number-解题报告
原题链接 https://leetcode.com/problems/single-number/Given an array of integers, every element appears twice except for one. Find that single one.找出唯一一个只出现一次的数。因为其他数肯定出现两次 又因为A^A = 0, 0^B = B;所以原创 2015-08-28 18:55:51 · 252 阅读 · 0 评论 -
LeetCode-Palindrome Linked List-解题报告
原题链接 https://leetcode.com/problems/palindrome-linked-list/Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?判断一个链表是否回文,O(n原创 2015-07-20 16:36:38 · 453 阅读 · 0 评论 -
LeetCode-Reverse Linked List-解题报告
原题链接 https://leetcode.com/problems/reverse-linked-list/Reverse a singly linked list.反转链表水过。/** * Definition for singly-linked list. * struct ListNode { * int val; * L原创 2015-07-08 18:36:37 · 291 阅读 · 0 评论 -
LeetCode-Implement Queue using Stacks-解题报告
原题链接https://leetcode.com/problems/implement-queue-using-stacks/Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes t原创 2015-07-07 15:58:18 · 447 阅读 · 0 评论 -
LeetCode-Min Stack-解题报告
原题链接https://leetcode.com/problems/min-stack/Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack. pop() -- Re原创 2015-07-07 16:01:28 · 316 阅读 · 0 评论 -
LeetCode-Power of Two-解题报告
原题链接https://leetcode.com/problems/power-of-two/Given an integer, write a function to determine if it is a power of two.直接看所给整数中位中1的个数 超过2个 就不是2的幂class Solution {public: bool isPow原创 2015-07-06 18:31:28 · 263 阅读 · 0 评论 -
LeetCode-Fraction to Recurring Decimal-解题报告
原题链接https://leetcode.com/problems/fraction-to-recurring-decimal/Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractiona原创 2015-07-03 19:48:00 · 335 阅读 · 0 评论 -
LeetCode-Compare Version Numbers解题报告
原题链接https://leetcode.com/problems/compare-version-numbers/Compare two version numbers version1 andversion2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.原创 2015-07-06 18:23:52 · 315 阅读 · 0 评论 -
LeetCode-Happy Number-解题报告
原题链接 https://leetcode.com/problems/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 int原创 2015-07-08 19:01:10 · 290 阅读 · 0 评论 -
LeetCode-Pow(x, n)-解题报告
原题链接 https://leetcode.com/problems/powx-n/Implement pow(x, n). 以前在算法书中看到过一个,将指数n写成2进制的情况。比如2^5 = 2^101 = 2^3 * 2^1class Solution {public: double myPow(double x, int n) { doubl原创 2015-07-08 21:02:57 · 332 阅读 · 0 评论 -
LeetCode-Sqrt(x)-解题报告
原题链接 https://leetcode.com/problems/sqrtx/Implement int sqrt(int x).Compute and return the square root of x.用数学的方法求解sqrt(x)可以使用牛顿迭代法,也可以使用二分法。我使用的是牛顿迭代法,前段时间看到一个求解x^(-2)的快速解就用的是牛顿迭代原创 2015-07-08 20:55:59 · 482 阅读 · 0 评论 -
LeetCode-Majority Element II-解题报告
原链接https://leetcode.com/problems/majority-element-ii/Given an integer array of size n, find all elements that appear more than⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) spa转载 2015-06-30 21:03:52 · 569 阅读 · 0 评论 -
LeetCode-The Skyline Problem-解题报告
LeetCode-The Skyline Problem-解题报告转载 2015-06-29 23:01:08 · 684 阅读 · 0 评论 -
LeetCode-Contains Duplicate III-解题报告
LeetCode-Contains Duplicate III-解题报告原创 2015-06-29 22:32:47 · 374 阅读 · 0 评论 -
LeetCode-Basic Calculator-解题报告
LeetCode-Basic Calculator-解题报告原创 2015-06-29 22:06:30 · 266 阅读 · 0 评论