每日一题
文章平均质量分 80
每日一题,保持对算法的敏感度。
A__loser
为人应当锐意进取,不为往事所羁
展开
-
Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined...原创 2019-12-05 18:58:00 · 345 阅读 · 0 评论 -
Simplify Path
Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.In a UNIX-style file system, a period . refers to the current directory. Furthermore, ...原创 2019-12-04 20:10:40 · 154 阅读 · 0 评论 -
Valid Anagram
Given two strings s and t , write a function to determine if t is an anagram of s.Example 1:Input: s = “anagram”, t = “nagaram”Output: trueExample 2:Input: s = “rat”, t = “car”Output: falseNote...原创 2019-12-02 21:01:06 · 212 阅读 · 0 评论 -
Longest Common Prefix
描述Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.Example 1:Input: [“flower”,“flow”,“flight”]Output: ...原创 2019-11-26 20:26:40 · 97 阅读 · 0 评论 -
Wildcard Matching
描述Implement wildcard pattern matching with support for ‘?’ and ‘’.‘?’ Matches any single character. '’ Matches any sequence of characters (including the empty sequence).The matching should cover th...原创 2019-11-25 21:02:38 · 101 阅读 · 0 评论 -
Add Binary
描述Given two binary strings, return their sum (also a binary string).For example,a = “11”b = “1”Return 100.分析无// Add Binary// 时间复杂度O(n),空间复杂度O(1)class Solution { public String addBinary(S...原创 2019-11-22 18:50:16 · 166 阅读 · 0 评论 -
String to Integer (atoi)
Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this...原创 2019-11-21 20:46:21 · 102 阅读 · 0 评论 -
Implement strStr()
描述Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.分析暴力算法的复杂度是 O(m*n),代码如下。更高效的的算法有KMP算法、Boyer-Mooer算法和Rabin-Karp算法。面试中...原创 2019-11-20 23:00:43 · 126 阅读 · 0 评论 -
Valid Palindrome
描述Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,“A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a pa...原创 2019-11-18 19:02:42 · 143 阅读 · 0 评论 -
234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) time and O(1)...原创 2019-11-15 10:23:25 · 184 阅读 · 0 评论 -
LRU Cache---如何实现一个简单的 LRU 缓存
描述Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if ...原创 2019-11-13 22:07:27 · 151 阅读 · 0 评论 -
Reorder List
描述:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You may not modify the values in the list’s nodes, only nodes itself may be changed.Example 1:Given 1->2-...原创 2019-11-12 21:42:33 · 141 阅读 · 0 评论 -
Linked List Cycle II
描述Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up: Can you solve it without using extra space?分析当fast与slow相遇时,slow肯定没有遍历完链表,而fast已经在环内循环了n圈...原创 2019-11-11 20:04:56 · 117 阅读 · 0 评论 -
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-11-10 20:01:05 · 108 阅读 · 0 评论 -
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:Input:{“KaTeX parse erro...原创 2019-11-09 22:37:01 · 119 阅读 · 0 评论 -
Reverse Nodes in k-Group
描述Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is...原创 2019-11-06 18:15:05 · 273 阅读 · 0 评论 -
Rotate List
Rotate List描述Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->nullptr and k = 2, return 4->5->1->2->3->...原创 2019-11-05 19:36:41 · 104 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1-&g...原创 2019-11-04 19:00:22 · 103 阅读 · 0 评论 -
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->2->3->3, return 1->2->3./...原创 2019-11-04 18:45:41 · 109 阅读 · 0 评论 -
Reverse Linked List II
描述Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->nullptr, m = 2 and n = 4,return 1->4->3->2->5->nullptr....原创 2019-10-29 18:53:47 · 104 阅读 · 0 评论 -
Partition List
描述Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of...原创 2019-10-31 17:35:21 · 127 阅读 · 0 评论 -
连通域问题
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a原创 2016-06-05 15:01:46 · 798 阅读 · 0 评论 -
最长上升子序列
题目描述:给定一个无序的整数数组,找到其中最长上升子序列的长度。示例:输入: [10,9,2,5,3,7,101,18]输出: 4解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。说明:可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。你算法的时间复杂度应该为 O(n2) 。进阶: 你能将算法的时间复杂度降低到 O(n log n) 吗?时间复杂度...原创 2018-10-29 00:11:25 · 138 阅读 · 0 评论