
ProgrammingTopics
编程算法题
流动熵
量化全球资金熵增轨迹,在无序中寻找可重复的有序片段
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
001.two-sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same element twice.Example:Given nums = [2, 7, 11, 15],原创 2022-02-20 20:26:36 · 171 阅读 · 0 评论 -
002.add-two-numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.You may assume the two numbers do n原创 2022-02-20 20:29:12 · 144 阅读 · 0 评论 -
003.longest-substring-without-repeating-characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the length of 1.Given "pwwkew", the answer is "wke",原创 2022-02-20 20:30:12 · 137 阅读 · 0 评论 -
004.median-of-two-sorted-arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2 = [2]The median is 2.0Example 2:nums1 = [1,原创 2022-02-20 20:31:16 · 213 阅读 · 0 评论 -
005.longest-palindromic-substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example:Input: "cbbd"Output: "bb"class Solution(object原创 2022-02-20 20:32:16 · 257 阅读 · 0 评论 -
006.zigzag-conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I GY I RAnd then read line by line: "PAHNAPLSIIGY...原创 2022-02-20 20:33:15 · 268 阅读 · 0 评论 -
007.reverse-integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought thr..原创 2022-02-20 20:34:32 · 230 阅读 · 0 评论 -
008.string-to-integer-atoi
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes:It is intended for this problem to be speci.原创 2022-02-20 20:38:06 · 184 阅读 · 0 评论 -
009.palindrome-number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the restriction of using extra原创 2022-02-20 20:40:11 · 241 阅读 · 0 评论 -
010.regular-expression-matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:原创 2022-02-20 20:43:29 · 194 阅读 · 0 评论 -
011.container-with-most-water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, suc原创 2022-02-21 11:36:06 · 460 阅读 · 0 评论 -
012.integer-to-roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution(object): def intToRoman(self, num): """ :type num: int :rtype: str """ ans = ""原创 2022-02-21 11:37:05 · 246 阅读 · 0 评论 -
013.roman-to-integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ d = {"I":1, "V": 5,原创 2022-02-21 11:38:08 · 246 阅读 · 0 评论 -
014.longest-common-prefix
Write a function to find the longest common prefix string amongst an array of strings.class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if len(strs) == 0:.原创 2022-02-21 11:39:16 · 189 阅读 · 0 评论 -
015.3sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain duplicate triplets.For example, given array S = [-1, 0,原创 2022-02-21 11:40:10 · 260 阅读 · 0 评论 -
016.3sum-closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2 ..原创 2022-02-21 11:42:13 · 187 阅读 · 0 评论 -
017.letter-combinations-of-a-phone-number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "原创 2022-02-21 11:43:29 · 244 阅读 · 0 评论 -
018.4sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution set must not contain duplicate quadruplets.For example, g原创 2022-02-21 11:44:41 · 224 阅读 · 0 评论 -
019.remove-nth-node-from-end-of-list
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.N...原创 2022-02-21 11:46:19 · 254 阅读 · 0 评论 -
020.valid-parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.class Solution(object): .原创 2022-02-21 11:47:18 · 235 阅读 · 0 评论 -
021.merge-two-sorted-lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val =原创 2022-02-22 09:13:16 · 257 阅读 · 0 评论 -
022.generate-parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "()()()"]class Solution(object): def gene...原创 2022-02-22 09:14:15 · 192 阅读 · 0 评论 -
023.merge-k-sorted-lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneimport heap.原创 2022-02-22 09:15:40 · 255 阅读 · 0 评论 -
024.swap-nodes-in-pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may not modify the values in the list, o原创 2022-02-22 09:16:50 · 256 阅读 · 0 评论 -
025.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.k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the原创 2022-02-22 09:18:16 · 510 阅读 · 0 评论 -
026.remove-duplicates-from-sorted-array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array nums =原创 2022-02-22 21:51:12 · 191 阅读 · 0 评论 -
027.remove-element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The order of elements can be changed. It doesn't matter wha原创 2022-02-22 21:52:24 · 119 阅读 · 0 评论 -
028.implement-strstr
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.class Solution(object): def strStr(self, haystack, needle): """ :type haystack: str :type needle.原创 2022-02-22 21:58:58 · 178 阅读 · 0 评论 -
029.divide-two-integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution(object): def divide(self, dividend, divisor): """ :type dividend: int :type divisor: int .原创 2022-02-22 22:00:14 · 125 阅读 · 0 评论 -
030.substring-with-concatenation-of-all-words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.For example, given:s原创 2022-02-22 22:12:54 · 249 阅读 · 0 评论 -
031.next-permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement原创 2022-02-23 21:51:21 · 185 阅读 · 0 评论 -
032.longest-valid-parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", which has length = 2.Another example is ")()())", where th原创 2022-02-23 21:54:04 · 270 阅读 · 0 评论 -
033.search-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).You are given a target value to search. If found in the array return its index, otherwise return -1.You may原创 2022-02-23 21:58:00 · 275 阅读 · 0 评论 -
034.search-for-a-range
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found in the array, return [-1, -1].For exa原创 2022-02-25 08:10:44 · 254 阅读 · 0 评论 -
035.search-insert-position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,原创 2022-02-25 08:11:58 · 178 阅读 · 0 评论 -
036.valid-sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially filled sudoku which is valid.Note:A valid Sudoku board (partially f原创 2022-02-25 08:15:08 · 313 阅读 · 0 评论 -
037.sudoku-solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku puzzle......and its solution numbers marked in red.class So.原创 2022-02-25 08:17:51 · 303 阅读 · 0 评论 -
038.count-and-say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2, then one 1" ...原创 2022-03-05 22:15:54 · 226 阅读 · 0 评论 -
039.combination-sum
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number of times.Note:All numbers (i..原创 2022-03-05 22:21:20 · 114 阅读 · 0 评论 -
040.combination-sum-ii
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.Note:All numbers (including target) will be posit.原创 2022-03-05 22:23:39 · 125 阅读 · 0 评论