
LeetCode技巧小本本
编程练手,保持手感。疲倦了可以换一种语言刷,语言特性不同刷起来感受差异还蛮大的
KINGHMY
人工智障炼丹师,人工自然语言处理工程师
展开
-
LeetCode-Sort Colors-排序
Sort Colors Java 排序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.原创 2016-09-12 21:41:12 · 524 阅读 · 0 评论 -
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. Y原创 2017-03-15 21:17:54 · 498 阅读 · 0 评论 -
Merge k Sorted Lists-LeetCode
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目描述:归并排序k个有序单链表。(感觉LeetCode说到排序默认即是自然会顺序,数字递增,字母按顺序)题目思路:先说一个由二路归并得来的思维简单、看似取巧实则复杂度奇高的方法:直接k路归并原创 2017-03-13 11:59:47 · 365 阅读 · 0 评论 -
Generate Parentheses-LeetCode
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:[ "((()))", "(()())", "(())()", "()(())原创 2017-03-12 16:14:24 · 421 阅读 · 0 评论 -
Valid Parentheses-LeetCode
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 va原创 2017-03-12 12:38:37 · 393 阅读 · 0 评论 -
Remove Nth Node From End of List-LeetCode
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原创 2017-03-12 10:52:17 · 295 阅读 · 0 评论 -
3Sum Closest-LeetCode
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 exact原创 2017-03-10 22:17:17 · 418 阅读 · 0 评论 -
3Sum-LeetCode
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原创 2017-03-10 19:11:01 · 331 阅读 · 0 评论 -
Container With Most Water-LeetCode
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). Fin原创 2017-03-04 22:26:19 · 360 阅读 · 0 评论 -
Reverse Integer && Palindrome Number-LeetCode
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Your function原创 2017-02-21 12:01:42 · 389 阅读 · 0 评论 -
String to Integer (atoi)-LeetCode
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 ca原创 2017-02-21 14:50:57 · 377 阅读 · 0 评论 -
ZigZag Conversion-LeetCode
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)原创 2017-02-20 22:21:22 · 311 阅读 · 0 评论 -
Longest Palindromic Substring-LeetCode
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.原创 2017-02-19 19:41:45 · 347 阅读 · 0 评论 -
Median of Two Sorted Arrays-LeetCode
题目大意:求得两个升序数组的中位数(根据两个数组长度和中位数定义稍有区分)题目限定:The overall run time complexity should be O(log (m+n)).题目思路:看到这个时间复杂度要求,我最先想到的是二叉树相关的数据结构。如果能做出一个平衡二叉树,左子树都是小于等于根节点,右子树都是大于根节点,那这题目岂不是很简单吗?简直无脑输出。仔细想想原创 2017-02-19 13:25:49 · 510 阅读 · 0 评论 -
Longest Substring Without Repeating Characters-LeetCode
题目:求得给定字符串的最长连续子字符串(不能有重复字符)题意的理解:1.首先是对于字符串的匹配,我想当然的理解为了由小写字母组成的字符串,因为给的例子都是小写字母啊,而且一般OJ里的不都是这样吗!果然大意失荆州,文化差异还是存在的,实际评测字符串为ascll码所表示的字符串。(交上去第一发就挂了,然后改代码!)2.题目所要求得的最长不重复子字符串,不就是两个相同的字符之间的最大距离吗?原创 2016-12-31 13:55:51 · 361 阅读 · 0 评论 -
Add Two Numbers-LeetCode
题目本意:单向链表模拟大数相加分析:链表结构已经给定了,需要自己完成大数链表的构造(PS:从头部到尾部存放的依次是从各位到高位的数据),然后按照加法法则去做就可以了。思路:如果完全按照加法法则去做的话,逻辑会比较复杂,因为每一位计算完毕都要判断是否进位,是否有哪个链表已经为空需要退出计算。所以讨巧点的思路就是借鉴归并排序的做法,现将两个链表每一位相加,保存在新链表里。随后在扫描一遍原创 2016-12-30 14:16:02 · 387 阅读 · 0 评论 -
Two sum-LeetCode
LeetCode单纯考算法,避免了java输入输出对程序设计的干扰。主要会给出错误的用例,简直很贴心!本题是要求出nums整形数中,两数之和为target的下标。下标小的在前,大的在后,而且“You may assume that each input would have exactly one solution.”。下面的代码,考虑到复杂度的缘故:最坏的情况下需要将nums原创 2016-12-30 12:11:38 · 280 阅读 · 0 评论 -
Reverse Nodes in k-Group-LeetCode
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 o原创 2017-03-15 22:43:08 · 448 阅读 · 0 评论