随笔分类 -  leetcode

permutations(全排列)
摘要:Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have the following permutations: 这题是列举所有情况,回溯。 每次都是从头开始遍 阅读全文

posted @ 2017-12-26 22:10 夜的第八章 阅读(335) 评论(0) 推荐(0)

Next Permutation 下一个排列
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib 阅读全文

posted @ 2017-12-26 21:24 夜的第八章 阅读(146) 评论(0) 推荐(0)

search in rotated sorted array
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You a 阅读全文

posted @ 2017-12-26 19:41 夜的第八章 阅读(144) 评论(0) 推荐(0)

valid sudoku(数独)
摘要:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled wit 阅读全文

posted @ 2017-12-26 17:09 夜的第八章 阅读(254) 评论(0) 推荐(0)

combination sum II
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each num 阅读全文

posted @ 2017-12-26 13:17 夜的第八章 阅读(158) 评论(0) 推荐(0)

Combination sum
摘要:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums 阅读全文

posted @ 2017-12-26 11:01 夜的第八章 阅读(167) 评论(0) 推荐(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 a 阅读全文

posted @ 2017-12-25 21:34 夜的第八章 阅读(216) 评论(0) 推荐(0)

4 sum
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic 阅读全文

posted @ 2017-12-25 19:54 夜的第八章 阅读(233) 评论(0) 推荐(0)

3 sum closest
摘要: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. 阅读全文

posted @ 2017-12-25 15:53 夜的第八章 阅读(186) 评论(0) 推荐(0)

3sum(从数组中找出三个数的和为0)
摘要: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 阅读全文

posted @ 2017-12-24 21:34 夜的第八章 阅读(1645) 评论(0) 推荐(0)

integer to roman
摘要:Input is guaranteed to be within the range from 1 to 3999. 将整数转成罗马数字。。下面答案比较厉害了。它将每个位置上(每位数)可能出现的情况先列出来,然后匹配 阅读全文

posted @ 2017-12-24 17:15 夜的第八章 阅读(133) 评论(0) 推荐(0)

String to Integer (atoi)
摘要:将字符串转成整数,跳过前面的空格。。然后转的时候注意防止溢出。。total=total*10+digit 这个检查溢出的方式要掌握:最大整数除以10比total小(说明total*10就要溢出),当最大整数除以10等于total,且余数小于digit,那么执行上面公式也会溢出。。 if(Intege 阅读全文

posted @ 2017-12-24 17:05 夜的第八章 阅读(180) 评论(0) 推荐(0)

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 阅读全文

posted @ 2017-12-24 16:19 夜的第八章 阅读(184) 评论(0) 推荐(0)

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: Example: 从字符串中找出最长的回文子串,该 阅读全文

posted @ 2017-12-24 15:31 夜的第八章 阅读(140) 评论(0) 推荐(0)

Longest Substring Without Repeating Characters
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the leng 阅读全文

posted @ 2017-12-23 21:31 夜的第八章 阅读(177) 评论(0) 推荐(0)

letter combinations of a phone number(回溯)
摘要:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho 阅读全文

posted @ 2017-12-23 20:02 夜的第八章 阅读(199) 评论(0) 推荐(0)

remove Nth Node from linked list从链表中删除倒数第n个元素
摘要: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 rem 阅读全文

posted @ 2017-12-23 16:46 夜的第八章 阅读(435) 评论(0) 推荐(0)

generate parentheses(生成括号)
摘要: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: 给 阅读全文

posted @ 2017-12-23 15:48 夜的第八章 阅读(172) 评论(0) 推荐(0)

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 contai 阅读全文

posted @ 2017-12-22 16:56 夜的第八章 阅读(185) 评论(0) 推荐(0)

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 阅读全文

posted @ 2017-12-22 14:45 夜的第八章 阅读(1329) 评论(0) 推荐(0)

导航