![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
经典题目
shida_csdn
Keep Running ...
展开
-
[leetcode-in-go] 0151-Reverse Words in a String
Given an input string, reverse the string word by word.Example 1:Input: “the sky is blue”Output: “blue is sky the”Example 2:Input: " hello world! "Output: “world! hello”Explanation: Your reve...原创 2019-07-21 23:26:16 · 181 阅读 · 0 评论 -
[leetcode-in-go] 0050-Pow(x, n)
Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, -2Output: ...原创 2019-07-11 22:30:35 · 169 阅读 · 0 评论 -
[leetcode-in-go] 0049- Group Anagrams
Given an array of strings, group anagrams together.Example:Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],Output:[[“ate”,“eat”,“tea”],[“nat”,“tan”],[“bat”]]Note:All inputs will be in lowe...原创 2019-07-11 22:05:20 · 295 阅读 · 0 评论 -
[leetcode-in-go] 0048- Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix dire...原创 2019-07-10 23:09:03 · 210 阅读 · 0 评论 -
[leetcode-in-go] 0047-Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[[1,1,2],[1,2,1],[2,1,1]]解题思路注意结果存储需要单独拷贝副本,放置被意外篡改切片因为扩容的...原创 2019-07-10 10:35:12 · 170 阅读 · 0 评论 -
[leetcode-in-go] 0009-Palindrome Number
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output: falseExplanation...原创 2019-07-09 22:41:44 · 274 阅读 · 0 评论 -
[leetcode-in-go] 0046-Permutations
Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]解题思路递归(cur + remain, *result)特别注意...原创 2019-07-08 23:59:07 · 143 阅读 · 0 评论 -
[leetcode-in-go] 0008-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-07-08 21:33:29 · 168 阅读 · 0 评论 -
[leetcode-in-go] 0006-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 G...原创 2019-07-02 23:24:41 · 134 阅读 · 0 评论 -
[leetcode-in-go] 0007-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 ...原创 2019-07-07 18:32:45 · 127 阅读 · 0 评论 -
[leetcode-in-go] 0069-Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and only t...原创 2019-07-11 23:22:34 · 180 阅读 · 0 评论 -
[leetcode-in-go] 0054-Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]Example...原创 2019-07-18 22:39:33 · 151 阅读 · 0 评论 -
[leetcode-in-go] 0149-Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.记录一种 n^2 解法:掌握最大公约数的求法小数是不准确的,难以作为 key,需要使用字符串代替除法结果func max(a, b int) int { if a > b { r...原创 2019-07-23 23:42:12 · 176 阅读 · 0 评论 -
头条面试题-统计有序数组里平方和的数目
给你一个有序整数数组,数组中的数可以是正数、负数、零,请实现一个函数,这个函数返回一个整数:返回这个数组所有数的平方值中有多少种不同的取值。举例:nums = {-1,1,1,1},那么你应该返回的是:1。因为这个数组所有数的平方取值都是1,只有一种取值nums = {-1,0,1,2,3}你应该返回4,因为nums数组所有元素的平方值一共4种取值:1,0,4,9解题思路双...原创 2019-07-21 12:12:02 · 527 阅读 · 0 评论 -
[leetcode-in-go] 0146-LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if the...原创 2019-07-21 11:05:15 · 179 阅读 · 0 评论 -
[leetcode-in-go] 0058-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-07-20 17:46:27 · 156 阅读 · 0 评论 -
[leetcode-in-go] 0053-Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation:...原创 2019-07-17 23:07:55 · 231 阅读 · 0 评论 -
[leetcode-in-go] 0057-Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example...原创 2019-07-20 17:29:06 · 186 阅读 · 0 评论 -
[leetcode-in-go] 0052-N-Queens II
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return the number of distinct solutions to the n-queens puzzl...原创 2019-07-17 21:57:48 · 152 阅读 · 0 评论 -
[leetcode-in-go] 0056-Merge Intervals
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps, m...原创 2019-07-20 15:30:48 · 162 阅读 · 0 评论 -
[leetcode-in-go] 0055-Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you ...原创 2019-07-19 22:41:34 · 173 阅读 · 0 评论 -
[leetcode-in-go] 0051-N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each so...原创 2019-07-16 23:51:49 · 310 阅读 · 0 评论 -
[leetcode-in-go] 0005-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 1:Input: “babad”Output: “bab”Note: “aba” is also a valid answer.Example ...原创 2019-07-02 23:08:07 · 124 阅读 · 0 评论 -
[leetcode-in-go] 0004-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)).You may assume nums1 and num...原创 2019-06-10 23:19:03 · 129 阅读 · 0 评论 -
[leetcode-in-go] 0003-Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:Input: ...原创 2019-06-09 10:36:16 · 198 阅读 · 0 评论 -
把二元查找树转变成排序的双向链表 Go 语言实现
题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。要求不能创建任何新的结点,只调整指针的指向。 10 / \ 6 14 / \ / \ 4 8 12 16转换成双向链表 4=6=8=10=12=14=16分析:1. 遇到树相关的问题,首先应该想到递归,递归地处理左右子树,获得左子树的 tail,右子树的 hea...原创 2018-10-17 23:22:46 · 321 阅读 · 0 评论 -
输入与输出 整理 机试必备
1. python 字符串多行输入while True: try: inputLine = raw_input() except: break2. 一行多个整数n,s = map(int,input().split())3. 输入数组(一行)nums = [int(x) for x in input().split()]原创 2018-03-22 10:04:01 · 577 阅读 · 0 评论 -
[经典题目] 链表反转 python
简短的递归解法,面试必备!class ListNode: def __init__(self, x): self.val = x self.next = Nonedef create_list(arr): pre = ListNode(0) tmp = pre for i in arr: tmp.next = L...原创 2018-03-29 22:55:43 · 651 阅读 · 0 评论 -
经典归并排序算法 -- Python
# -*- coding: UTF-8 -*-def merge(a,b): c = [] i = 0 j = 0 while i < len(a) and j < len(b): if a[i] < b[j]: c.append(a[i]) i += 1 else: c.append(b[j]) j += 1 c.extend(a[i...原创 2018-03-04 16:50:32 · 197 阅读 · 0 评论 -
经典快速排序算法 -- Python
# -*- coding: UTF-8 -*-def parttion(arr,left,right): key = arr[left] # left 而非 0 while left < right: while left < right and arr[right] >= key: # 一不等 一带等 right -= 1 arr[left] = arr[r...原创 2018-03-04 16:33:44 · 252 阅读 · 0 评论 -
[leetcode] Basic Calculator 使用堆栈计算表达式的值
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em原创 2018-02-24 09:51:45 · 511 阅读 · 0 评论 -
[LeetCode] Sort Colors 颜色排序
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers转载 2018-02-22 10:58:14 · 235 阅读 · 0 评论 -
二叉树的水平(层次)遍历 -- Python
import Queueclass node(object): def __init__(self,data=None,left=None,right=None): self.data=data self.left=left self.right=right def print_by_layer(tree): if not tr...原创 2018-03-07 00:03:08 · 553 阅读 · 0 评论 -
经典回溯算法之八皇后问题 -- Python
# -*- coding: UTF-8 -*-import copy # 使用全局变量保存结果global arr global countglobal mlist# 定义条件判定函数def conflict(index,col): global arr for i in range(index): if arr[i][col] == 1: return True...原创 2018-03-06 23:17:49 · 868 阅读 · 1 评论 -
旋转字符串
题目描述给定一个字符串,要求把字符串前面的若干个字符移动到字符串的尾部,如把字符串“abcdef”前面的2个字符'a'和'b'移动到字符串的尾部,使得原字符串变成字符串“cdefab”。请写一个函数完成此功能,要求对长度为n的字符串操作的时间复杂度为 O(n),空间复杂度为 O(1)。分析与解法三步反转法:例如,字符串 abcdef ,若要让def翻转到abc的前头,只要按照下述3...原创 2018-10-16 11:02:36 · 378 阅读 · 1 评论 -
字符串转换成整数
题目描述输入一个由数字组成的字符串,把它转换成整数并输出。例如:输入字符串"123",输出整数123。给定函数原型int StrToInt(const char *str) ,实现字符串转换成整数的功能,不能使用库函数atoi。package mainimport ( "strings" "fmt")func atoi(str string) (int32, error...原创 2018-10-31 14:42:07 · 273 阅读 · 0 评论 -
字符串包含
题目描述给定两个分别由字母组成的字符串A和字符串B,字符串B的长度比字符串A短。请问,如何最快地判断字符串B中所有字母是否都在字符串A里?为了简单起见,我们规定输入的字符串只包含大写英文字母,请实现函数bool StringContains(string &A, string &B)比如,如果是下面两个字符串:String 1:ABCDString 2:BAD...原创 2018-10-30 14:53:25 · 327 阅读 · 0 评论 -
[leetcode-in-go] 0002-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 i...原创 2019-06-08 11:24:47 · 153 阅读 · 0 评论 -
[leetcode-in-go] 0001-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 e...原创 2019-06-08 10:46:33 · 166 阅读 · 0 评论 -
QuickSelect 查找第 K 小的元素
Quick select 算法通常用来在未排序的数组中寻找第 k 小/第 k 大的元素。其方法类似于 Quick sort。本质上是通过多次快速排序,当某次快速排序的枢纽元素恰好下标为 k-1 时,结束查找~package mainimport "fmt"func core(nums []int, k, start, end int) int { left, right := ...原创 2018-12-19 11:09:37 · 700 阅读 · 0 评论