LeetCode(Go)
MarvinYSh
这个作者很懒,什么都没留下…
展开
-
344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".func reverseString(s string) string { rs := []rune(s) for i, j := 0, len...原创 2018-05-23 15:24:46 · 160 阅读 · 0 评论 -
7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with an envir...原创 2018-05-23 16:22:36 · 183 阅读 · 0 评论 -
561. Array Partition I
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 poss...原创 2018-05-28 13:44:53 · 121 阅读 · 0 评论 -
766. Toeplitz Matrix
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the matrix is Toeplitz. Example 1:Input: matrix = [[1,2,...原创 2018-05-28 14:07:50 · 163 阅读 · 0 评论 -
566. Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dimensi...原创 2018-05-28 16:05:51 · 158 阅读 · 0 评论 -
387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note: You may assume...原创 2018-05-24 14:07:39 · 159 阅读 · 1 评论 -
717. 1-bit and 2-bit Characters
We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Now given a string represented by several bits. Re...原创 2018-05-29 18:38:07 · 180 阅读 · 0 评论 -
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 su...原创 2018-05-29 18:41:02 · 174 阅读 · 0 评论 -
832. Flipping an Image
Given a binary matrix A, 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 example...原创 2018-05-28 11:36:45 · 147 阅读 · 0 评论 -
1. 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 el...原创 2018-05-23 12:01:56 · 131 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Given a sorted array nums, 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 by modifying...原创 2018-05-21 16:41:13 · 177 阅读 · 0 评论 -
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 ...原创 2018-05-21 16:59:39 · 191 阅读 · 0 评论 -
189. Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,3,...原创 2018-05-21 17:14:49 · 133 阅读 · 0 评论 -
217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is ...原创 2018-05-22 10:16:26 · 135 阅读 · 0 评论 -
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 using ...原创 2018-05-22 12:25:00 · 121 阅读 · 0 评论 -
350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as many times as it sho...原创 2018-05-22 15:00:06 · 154 阅读 · 0 评论 -
66. Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element i...原创 2018-05-22 17:21:53 · 172 阅读 · 0 评论 -
283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Note:You must do this in-place without making a copy of the...原创 2018-05-23 00:07:30 · 138 阅读 · 0 评论 -
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 always...原创 2018-05-29 18:42:40 · 156 阅读 · 0 评论