
算法和数据结构
Simple_ R
这个作者很懒,什么都没留下…
展开
-
5051. Valid Boomerang
Aboomerangis a set of 3 points that are all distinct andnotin a straight line.Given a listof three points in the plane, return whether these points are a boomerang.Example 1:Input: [[1...原创 2019-05-05 11:42:46 · 369 阅读 · 0 评论 -
Leetcode 1012. Complement of Base 10 Integer
Every non-negative integerNhas a binary representation. For example,5can be represented as"101"in binary,11as"1011"in binary, and so on. Note that except forN = 0, there are no leading z...原创 2019-03-17 12:16:34 · 207 阅读 · 0 评论 -
Leetcode 400. Nth Digit
Find thenthdigit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:nis positive and will fit within the range of a 32-bit signed integer (n< 231).Example 1:Inp...原创 2019-03-16 00:51:17 · 154 阅读 · 0 评论 -
Leetcode 1005. Maximize Sum Of Array After K Negations
Given an arrayAof integers, wemustmodify the array in the following way: we choose aniand replaceA[i]with-A[i], and we repeat this processKtimes in total. (We may choose the same indexi...原创 2019-03-10 12:58:32 · 323 阅读 · 0 评论 -
Leetcode 1003. Check If Word Is Valid After Substitutions
We are given that the string"abc"is valid.From any valid stringV, we may splitVinto two piecesXandYsuch thatX + Y(Xconcatenated withY) is equal toV. (XorYmay be empty.) Then,X + ...原创 2019-03-03 12:24:51 · 412 阅读 · 0 评论 -
Leetcode 1002. Find Common Characters
Given an arrayAof strings made only from lowercase letters, return a list of all characters that show up in all strings within the list(including duplicates).For example, if a character occurs 3...原创 2019-03-03 12:23:42 · 721 阅读 · 0 评论 -
基于数组实现循环队列 Implementation of Circular Queue Based on Static Array
题目来源:https://leetcode.com/explore/learn/card/queue-stack/228/first-in-first-out-data-structure/1337/class MyCircularQueue { int[] circularQueue = null; int headPos, rearPos = -1, amount; ...原创 2019-02-20 18:31:15 · 266 阅读 · 0 评论 -
Leetcode 997. Find the Town Judge
In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.If the town judge exists, then:The town judge trusts nobody. Everybody (...原创 2019-02-24 11:57:37 · 496 阅读 · 0 评论 -
Leetcode 409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not cons...原创 2019-02-18 10:00:25 · 307 阅读 · 0 评论 -
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...原创 2019-02-17 23:33:04 · 173 阅读 · 0 评论 -
Leetcode 1013. Pairs of Songs With Total Durations Divisible by 60
In a list of songs, thei-thsong has a duration oftime[i]seconds.Return the number of pairs of songs for which their totalduration in seconds is divisible by60. Formally, we want the number ...原创 2019-03-17 22:29:33 · 231 阅读 · 0 评论 -
Leetcode 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree[1,2,2,3,4,4,3]is symmetric: 1 / \ 2 2 / \ / \3 4 4 3...原创 2019-03-17 23:47:13 · 160 阅读 · 0 评论 -
Leetcode 1021. Remove Outermost Parentheses
A valid parentheses string is either empty(""),"(" + A + ")", orA + B, whereAandBare valid parentheses strings, and+represents string concatenation. For example,"","()","(())()", and"(()...原创 2019-04-07 13:13:40 · 416 阅读 · 0 评论 -
Leetcode 1028. Convert to Base -2
Given a numberN, return a string consisting of"0"s and"1"sthat represents its value in base-2(negative two).The returned string must have no leading zeroes, unless the string is"0".Exam...原创 2019-03-31 18:05:14 · 310 阅读 · 0 评论 -
Leetcode 1030. Next Greater Node In Linked List
We are given a linked list withheadas the first node. Let's number thenodes in the list:node_1, node_2, node_3, ...etc.Each node may have anext largervalue: fornode_i,next_larger(node_i)...原创 2019-03-31 13:32:16 · 285 阅读 · 0 评论 -
Leetcode 1029. Binary Prefix Divisible By 5
Given an arrayAof0s and1s, considerN_i: the i-th subarray fromA[0]toA[i]interpretedas a binary number (from most-significant-bit to least-significant-bit.)Return a list of booleansanswer...原创 2019-03-31 13:31:20 · 344 阅读 · 0 评论 -
1023. Binary String With Substrings Representing 1 To N
Given a binary stringS(a string consisting only of '0' and '1's) and a positive integerN, return true if and only if for every integer X from 1 to N, the binary representation of X is a substring ...原创 2019-03-24 11:11:05 · 421 阅读 · 0 评论 -
Leetcode 114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look like:1 \ 2 \ ...原创 2019-03-30 16:32:20 · 196 阅读 · 0 评论 -
Leetcode 476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range of a ...原创 2019-03-30 14:20:25 · 178 阅读 · 0 评论 -
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 integerposwhich represents the position (0-indexed)in the linked list where tail c...原创 2019-03-24 22:03:29 · 167 阅读 · 0 评论 -
Leetcode 438. Find All Anagrams in a String
Given a stringsand anon-emptystringp, find all the start indices ofp's anagrams ins.Strings consists of lowercase English letters only and the length of both stringssandpwill not be larg...原创 2019-03-12 23:43:30 · 337 阅读 · 1 评论 -
Leetcode 993. Cousins in Binary Tree
In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.Two nodes of a binary tree are cousins if they have the same depth, but have different parents.We...原创 2019-02-17 12:13:52 · 457 阅读 · 0 评论 -
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 Hamming distance.Note:0 ≤ x, y < 2...原创 2019-02-16 15:55:17 · 215 阅读 · 0 评论 -
队列与深度优先 Queue and BFS
Two main scenarios of using BFS: do traversal or find the shortest path. Typically, it happens in a tree or a graph.In some cases, we can abstract a specific question into a tree or a graph. The nod...原创 2019-02-21 17:31:00 · 372 阅读 · 0 评论 -
Leetcode 978. Longest Turbulent Subarray
A subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent if and only if:For i <= k < j, A[k] > A[k+1] when k is odd, and A[k] < A[k+1] when k is even; OR, for i <= k < j, ...原创 2019-01-20 12:04:26 · 298 阅读 · 0 评论 -
辗转相除法解析
辗转相除法基于如下原理:两个整数的最大公约数等于其中较小的数和两数的相除余数的最大公约数。 to complete原创 2019-01-19 10:14:29 · 495 阅读 · 0 评论 -
Leetcode 976. Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths.If it is impossible to form any triangle of non-zero area, return...原创 2019-01-13 12:17:53 · 282 阅读 · 0 评论 -
Leetcode 973. K Closest Points to Origin
We have a list of points on the plane. Find the K closest points to the origin (0, 0).(Here, the distance between two points on a plane is the Euclidean distance.)You may return the answer in an...原创 2019-01-13 12:16:59 · 345 阅读 · 0 评论 -
Leetcode 829. Consecutive Numbers Sum
Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers?Example 1:Input: 5Output: 2Explanation: 5 = 5 = 2 + 3Example 2:Input: 9Output: 3Expla...原创 2019-01-07 01:44:11 · 294 阅读 · 0 评论 -
Leetcode 791. Custom Sort String
S and T are strings composed of lowercase letters. In S, no letter occurs more than once.S was sorted in some custom order previously. We want to permute the characters of T so that they match the ...原创 2019-01-07 00:37:36 · 152 阅读 · 0 评论 -
一种图的算法——并查集
这个文章是几年前水acm的时候转的, 当时也不知道作者是谁, 要是有人知道的话说一下吧并查集是我暑假从高手那里学到的一招,觉得真是太精妙的设计了。以前我无法解决的一类问题竟然可以用如此简单高效的方法搞定。不分享出来真是对不起party了。(party:我靠,关我嘛事啊?我跟你很熟么?)来看一个实例,杭电1232畅通工程...转载 2018-12-15 18:00:45 · 275 阅读 · 0 评论 -
排序算法
一,常见排序算法排序算法 是否稳定 时间复杂度 空间复杂度 冒泡排序 插入排序 选择排序 快速排序 基数排序 希尔排序 ...原创 2018-12-06 22:09:55 · 173 阅读 · 0 评论 -
二叉树深度优先遍历和广度优先遍历(Java实现)
结点类 private static class TreeNode { private int value; TreeNode left, right; public TreeNode(int value) { this.value = value; } } 构建二叉树 ...原创 2018-12-06 20:34:28 · 885 阅读 · 0 评论 -
Leetcode 977. Squares of a Sorted Array
Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order. Example 1:Input: [-4,-1,0,3,10]Output: [0,1,9,...原创 2019-01-20 12:05:38 · 641 阅读 · 0 评论 -
Leetcode 77. Combinations
todo原创 2019-01-20 13:04:14 · 167 阅读 · 0 评论 -
Leetcode 985. Sum of Even Numbers After Queries
We have an array A of integers, and an array queries of queries.For the i-th query val = queries[i][0], index = queries[i][1], we add val to A[index]. Then, the answer to the i-th query is the sum...原创 2019-02-03 18:27:59 · 456 阅读 · 0 评论 -
Leetcode 112. Path Sum
Related tops: DFS & RecursionGiven 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 equals the given sum.Note: A leaf i...原创 2019-01-28 12:05:56 · 153 阅读 · 0 评论 -
Leetcode 984. String Without AAA or BBB
贪心算法Given two integers A and B, return any string S such that:S has length A + B and contains exactly A 'a' letters, and exactly B 'b'letters; The substring 'aaa' does not occur in S; The subst...原创 2019-01-27 22:57:30 · 372 阅读 · 0 评论 -
Leetcode 561. Array Partition
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as pos...原创 2019-01-27 21:45:35 · 172 阅读 · 0 评论 -
Leetcode 784. Letter Case Permutation
backtracking + dfs + recursive 784. Letter Case PermutationEasy49661FavoriteShareGiven a string S, we can transform every letter individually to be lowercase or uppercase to create another st...原创 2019-01-27 19:29:45 · 177 阅读 · 0 评论