
Leetcode
YuanTheCoder
转码之路
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode 832. Flipping an Image, Java解法
Given a binary matrixA, we want to flip the image horizontally, then invert it, and return the resulting image.To flip an image horizontally means that each row of the image is reversed. For examp...原创 2019-07-12 10:01:35 · 203 阅读 · 0 评论 -
Leetcode 905. Sort Array By Parity, Java解法
Given an arrayAof non-negative integers, return an array consisting of all the even elements ofA, followed by all the odd elements ofA.You may return any answer array that satisfies this conditi...原创 2019-07-12 10:34:30 · 232 阅读 · 0 评论 -
Leetcode 977. Squares of a Sorted Array, Java解法
Given an array of integersAsorted 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,16,1...原创 2019-07-12 11:16:39 · 431 阅读 · 0 评论 -
Leetcode 561. Array Partition I, Java解法
Given an array of2nintegers, your task is to group these integers intonpairs 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 poss...原创 2019-07-12 12:37:46 · 306 阅读 · 0 评论 -
Leetcode 1051. Height Checker, Java解法
Students are asked to stand in non-decreasing order of heights for an annual photo.Return the minimum number of students not standing in the right positions. (This is the number of students that mu...原创 2019-07-12 14:40:32 · 584 阅读 · 1 评论 -
Leetcode[498, 54, 118 ] Array 专题(2) 2D Array
此类题目就是花式遍历2维数组,我个人并不喜欢。498.Diagonal TraverseGiven a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image.Example:I...原创 2019-07-19 11:51:34 · 188 阅读 · 0 评论 -
亚麻 OA 2019 题目
Most Common Word Prison Cells After N Days K Closest Points to Origin Reorder Log Files Partition Labels Min Cost to Add New Roads Min distance to remove the obstacle Roll Dice Min Cost to Con...原创 2019-07-29 23:08:57 · 2453 阅读 · 0 评论 -
Leetcode 1089. Duplicate Zeros, java解法 及Queue的使用
Given a fixed lengtharrayarrof integers, duplicate each occurrence of zero, shifting the remaining elements to the right.Note that elements beyond the length of the original array are not written...原创 2019-07-20 17:21:58 · 358 阅读 · 0 评论 -
Leetcode [141, 142] Linked List Cycle,java解法
141 Linked List CycleGiven 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 l...原创 2019-07-25 09:43:24 · 364 阅读 · 0 评论 -
Leetcode[217, 136, 349, 202] HashTable 小专题 1 HashSet
HashTableis a data structure which organizes data usinghash functionsin order to supportquick insertion and search.In this article, we will take a look at the principle of the hash table.一 自己定...原创 2019-07-21 15:43:27 · 218 阅读 · 0 评论 -
Java中 Queue队列的用法及例子
1. Usage 用法// "static void main" must be defined in a public class.public class Main { public static void main(String[] args) { // 1. Initialize a queue. Queue<Integer> q...原创 2019-08-01 22:33:08 · 491 阅读 · 0 评论 -
狗家 Online Assessment
License Key Formatting Unique Email Addresses Fruit Into Baskets Odd Even Jump Maximum Area Serving Cake Min Days to Bloom Fill Matrix Compare Strings Largest Subarray Length K Decreasing Sub...原创 2019-08-08 23:57:26 · 416 阅读 · 0 评论 -
Leetcode 38. Count and Say Java解法
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211is read off as"one 1"or11.11is read off ...原创 2019-08-24 23:19:18 · 209 阅读 · 0 评论 -
Leetcode 250. Count Univalue Subtrees 谷歌面试, Java解法详解
这是一道谷歌会考的题目Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.Example :Input: root = [5,1,5,5,5,null,5] ...原创 2019-08-22 10:19:58 · 398 阅读 · 0 评论 -
leetcode 70. Climbing Stairs Java解法,Amazon面试
You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note:Givennwill be a positive...原创 2019-08-22 10:39:58 · 204 阅读 · 0 评论 -
Leetcode 1085. Sum of Digits in the Minimum Number, Java解法
Given an arrayAof positive integers, letSbe the sum of the digits of the minimal element ofA.Return 0 ifSis odd, otherwise return 1.Example 1:Input: [99,77,33,66,55]Output: 1Explana...原创 2019-07-11 20:03:08 · 279 阅读 · 0 评论 -
Leetcode 283. Move Zeroes java解法
Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You m...原创 2019-07-16 08:58:48 · 315 阅读 · 0 评论 -
Leetcode 922. Sort Array By Parity II , Java解法
Given an arrayAof non-negative integers, half of the integers in A are odd, and half of the integers are even.Sort the array so that wheneverA[i]is odd,iis odd; and wheneverA[i]is even,iis...原创 2019-07-12 20:10:22 · 400 阅读 · 0 评论 -
Leetcode 11. Container With Most Water , Java解法
Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two...原创 2019-07-13 08:59:06 · 218 阅读 · 0 评论 -
Leetcode 1108. Defanging an IP Address, Java解法
Given a valid (IPv4) IPaddress, return a defanged version of that IP address.AdefangedIP addressreplaces every period"."with"[.]".Example 1:Input: address = "1.1.1.1"Output: "1[.]1[....原创 2019-07-09 23:43:23 · 517 阅读 · 0 评论 -
Leetcode 509. Fibonacci Number , Java 解法
TheFibonacci numbers, commonly denotedF(n)form a sequence, called theFibonacci sequence, such that each number is the sum of the two preceding ones, starting from0and1. That is,F(0) = 0, F(...原创 2019-07-14 09:08:49 · 426 阅读 · 0 评论 -
Leetcode 999. Available Captures for Rook , Java解法。
On an 8 x 8 chessboard, there is one white rook. There also may be empty squares, white bishops, and black pawns. These are given as characters 'R', '.', 'B', and 'p' respectively. Uppercase charact...原创 2019-07-14 11:39:22 · 233 阅读 · 0 评论 -
Leetcode 760. Find Anagram Mappings, java解法
Given two listsAandB, andBis an anagram ofA.Bis an anagram ofAmeansBis made by randomizing the order of the elements inA.We want to find anindex mappingP, fromAtoB. A mappingP[i] =...原创 2019-07-10 13:51:48 · 210 阅读 · 0 评论 -
Leetcode 1064. Fixed Point, Java解法
Given an arrayAof distinct integers sorted in ascending order, return the smallest indexithat satisfiesA[i] == i. Return-1if no suchiexists.Example 1:Input: [-10,-5,0,3,7]Output: 3...翻译 2019-07-10 14:22:34 · 814 阅读 · 0 评论 -
Leetcode 1002. Find Common Characters, Java 解法
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-07-14 20:56:08 · 325 阅读 · 0 评论 -
Leetcode 867. Transpose Matrix, Java解法
Given amatrixA, return the transpose ofA.The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.Example 1:Input: [[1,2,3]...原创 2019-07-14 21:11:57 · 210 阅读 · 0 评论 -
Leetcode 1. Two Sum, Java 解法
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-07-10 20:15:22 · 225 阅读 · 0 评论 -
Leetcode [724, 747,66] Array专题 (1)
Operations in Array// "static void main" must be defined in a public class.public class Main { public static void main(String[] args) { // 1. Initialize int[] a0 = new int[5];...原创 2019-07-15 13:12:46 · 176 阅读 · 0 评论 -
Leetcode 771. Jewels and Stones Java解法
You're given stringsJrepresenting the types of stones that are jewels, andSrepresenting the stones you have. Each character inSis a type of stone you have. You want to know how many of the ston...翻译 2019-07-05 23:59:35 · 229 阅读 · 0 评论 -
Leetcode 1086. High Five Java 解法
先吐槽一下这个难度,咋也不能是easy啊,和其他easy的不在一个量级。Given a list of scores of different students, return the average score of each student'stop five scoresinthe order of each student's id.Each entryitems[i]h...原创 2019-07-11 16:11:37 · 1403 阅读 · 0 评论 -
Leetcode 1119. Remove Vowels from a String, Java解法
Given a stringS, remove the vowels'a','e','i','o', and'u'from it, and return the new string.Example 1:Input: "leetcodeisacommunityforcoders"Output: "ltcdscmmntyfrcdrs"Example 2:Inpu...原创 2019-07-15 23:52:40 · 345 阅读 · 0 评论 -
Intro to Dynamic Programming 动态规划专题 [1]
1 动态规划简介动态规划在查找有很多重叠子问题的情况的最优解时有效。它将问题重新组合成子问题。为了避免多次解决这些子问题,它们的结果都逐渐被计算并被保存,从简单的问题直到整个问题都被解决。因此,动态规划保存递归时的结果,因而不会在解决同样的问题时花费时间。动态规划只能应用于有最优子结构的问题。最优子结构的意思是局部最优解能决定全局最优解(对有些问题这个要求并不能完全满足,故有时需要引入一定的近...转载 2019-08-28 00:59:56 · 229 阅读 · 0 评论