- 博客(131)
- 收藏
- 关注
原创 LeetCode 17:Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is give...
2019-09-26 10:37:01
156
原创 LeetCode 401:Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit on t...
2019-09-26 09:16:17
161
原创 LeetCode 653:Two Sum IV - Input is a BST
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Example 2:C++bool findTarget(TreeNod...
2019-09-24 13:54:50
135
原创 LeetCode 1124:Longest Well-Performing Interval
We are given hours, a list of the number of hours worked per day for a given employee.A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.A ...
2019-09-24 09:46:45
290
原创 LeetCode 172:Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Example 1:Input: 3Output: 0Explanation: 3! = 6, no trailing zero.Example 2:Input: 5Output: 1Explanation: 5! = 120, one trailing z...
2019-09-20 13:54:06
122
原创 LeetCode 171:Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28 ...Example 1:Input: “A”...
2019-09-20 11:00:18
125
原创 LeetCode 169: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 that the array is non-empty and the majority element alway...
2019-09-20 10:26:30
134
原创 LeetCode 168:Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB ...Example 1:Input: 1...
2019-09-20 09:33:55
131
原创 LeetCode 167:Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers s...
2019-09-18 12:07:31
115
原创 LeetCode 166:Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.Examp...
2019-09-18 11:14:01
120
原创 LeetCode 165:Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0.You may assume that the version strings are non-empty and...
2019-09-17 09:47:27
116
原创 LeetCode 162:Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.The array may contain multiple peaks, i...
2019-09-17 09:16:01
110
原创 LeetCode 160:Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:C++ ListNode *getIntersectionNode(ListNode *headA, ListNod...
2019-09-16 09:44:18
145
原创 LeetCode 155: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() – Removes the element on top of the stack.top() – Get the ...
2019-09-16 09:23:41
131
原创 LeetCode 153:Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.You may assume no dupli...
2019-09-11 10:30:07
122
原创 LeetCode 152:Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] has ...
2019-09-11 09:39:54
172
原创 LeetCode 151:Reverse Words in a String
Given an input string, reverse the string word by word.Example 1:Input: “the sky is blue”Output: “blue is sky the”Example 2:Input: " hello world! "Output: “world! hello”Explanation: Your reve...
2019-09-10 22:21:53
121
原创 LeetCode 150:Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Note:Division between two integers sho...
2019-09-09 09:28:20
110
原创 LeetCode 148:Sort List
Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1->0-&...
2019-09-07 14:25:29
108
原创 LeetCode 147:Insertion Sort List
Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element (...
2019-09-07 11:27:55
124
原创 LeetCode 146:LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if the...
2019-09-07 10:38:24
75
原创 LeetCode 144:Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes’ values.Example:Input: [1,null,2,3]Output: [1,2,3]C++vector<int> preorderTraversal(TreeNode* root) { vector<int&g...
2019-09-06 11:16:29
125
原创 LeetCode 142:Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-in...
2019-09-06 10:57:05
119
原创 Leetcode 141:Linked List Cycle
Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail con...
2019-09-06 09:44:20
128
原创 Leetcode 138:Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.Example 1:C++ RandomListNode *co...
2019-09-05 16:22:54
100
原创 Leetcode 137:Single Number II
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime complexity. C...
2019-09-05 15:20:43
103
原创 Leetcode 136:Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usin...
2019-09-05 14:46:31
88
原创 Leetcode 134:Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its n...
2019-09-05 14:29:44
98
原创 Leetcode 133:Clone Graph
Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph. Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.Example:In...
2019-09-05 11:22:06
156
原创 Leetcode 131:Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.Example:Input: “aab”Output:[[“aa”,“b”],[“a”,“a”,“b”]]...
2019-09-04 15:44:59
114
原创 Leetcode 130:Surrounded Regions
Given a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.A region is captured by flipping all 'O’s into 'X’s in that surrounded region.Example:X X X XX O O XX...
2019-09-04 14:45:33
95
原创 Leetcode 129:Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total ...
2019-09-04 13:51:15
81
原创 Leetcode 127:Word Ladder
Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a tim...
2019-09-04 11:21:36
85
原创 Leetcode 125:Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Example...
2019-09-04 09:48:14
110
原创 Leetcode 122:Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one...
2019-09-02 10:54:08
158
原创 Leetcode 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 (i.e., buy one and sell one share of the stock), ...
2019-09-02 10:44:09
117
原创 Leetcode 120:Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangleThe minimum path sum from top to...
2019-09-02 10:29:36
90
原创 Leetcode 119:Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal’s triangle.Note that the row index starts from 0.In Pascal’s triangle, each number is the sum of the two numbers dir...
2019-09-02 09:51:25
95
原创 Leetcode 118:Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.In Pascal’s triangle, each number is the sum of the two numbers directly above it.Example:C++ vector<vecto...
2019-09-02 09:30:22
113
原创 单例模式--懒汉式与饿汉式
1:简述单例模式(Singleton Pattern)是一种常用的设计模式,它属于创建者模式。单例模式只允许有一个实例,通过构造函数私有化的方式隐藏对象创建入口,取而代之的是提供公共接口用于获取类的单例。其应用场景广泛,例如创建管理类(只需要一个管理实体),或者应用于对象需要限定唯一性的场景等。注意不要滥用单例模式,否则会导致代码维护困难。单例模式首先需要一个私有的、静态的单例对象(或者指针)...
2019-09-01 20:08:39
106
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人