![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
K.Sun
这个作者很懒,什么都没留下…
展开
-
字符串转整数(String to Integer (atoi))
public class StringtoInteger { public int myAtoi(String str) { if (str == null) return 0; str = str.trim(); if (str.equals("") || str.equals("+") || str.equals(原创 2016-10-10 23:02:18 · 1088 阅读 · 0 评论 -
最长回文子字符串(Longest Palindromic Substring)
Given a string S, find thelongest palindromic substring in S. You may assume that the maximumlength ofS is 1000, and there exists one unique longest palindromicsubstring.原创 2016-10-11 22:12:04 · 1191 阅读 · 0 评论 -
没有重复字符的最长子字符串(Longest Substring Without Repeating Characters)
Given a string, find the length of the longest substring without repeating characters.原创 2016-10-12 21:09:02 · 462 阅读 · 0 评论 -
在数组中找出四个数字的和等于指定数字(4Sum)
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 which gives the sum of target.Note: The solution原创 2016-10-13 13:44:05 · 3039 阅读 · 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 for better legibility)P A H NA P L S I I原创 2016-10-12 22:44:49 · 676 阅读 · 0 评论 -
Island Perimeter
题目地址:https://leetcode.com/problems/island-perimeter/You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/v原创 2016-11-28 21:34:41 · 1016 阅读 · 0 评论 -
Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2016-11-29 14:27:52 · 309 阅读 · 0 评论 -
Single Number
题目地址:https://leetcode.com/problems/single-number/Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexi原创 2016-11-29 14:59:52 · 246 阅读 · 0 评论 -
Find the Difference
题目地址:https://leetcode.com/problems/find-the-difference/Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter原创 2016-11-29 18:20:49 · 288 阅读 · 0 评论 -
Power of Three
题目地址:https://leetcode.com/problems/power-of-three/Given an integer, write a function to determine if it is a power of three.Follow up: Could you do it without using any loop / recursion? 判断一个数是不是3的幂。首原创 2016-12-10 18:55:45 · 175 阅读 · 0 评论 -
Power of Two
题目地址:https://leetcode.com/problems/power-of-two/Given an integer, write a function to determine if it is a power of two. 这次是判断一个数字是不是2的幂。好,假如一个数字是2的幂,那么它对应的2进制是长这样的:1000000000000就是最高位一个1,后面跟一堆0。如果把刚才这个原创 2016-12-10 19:08:44 · 250 阅读 · 0 评论 -
Power of Four
题目地址:https://leetcode.com/problems/power-of-four/Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example: Given num = 16, return true. Given num = 5, return fal原创 2016-12-10 21:21:16 · 208 阅读 · 0 评论 -
Add Strings
题目地址:https://leetcode.com/problems/add-strings/Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100.Both原创 2016-12-10 22:30:39 · 313 阅读 · 0 评论 -
Convert a Number to Hexadecimal
题目地址:https://leetcode.com/problems/convert-a-number-to-hexadecimal/Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All let原创 2016-12-10 23:59:10 · 342 阅读 · 0 评论 -
Binary Watch
题目地址:https://leetcode.com/problems/binary-watch/A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a ze原创 2016-12-11 14:20:24 · 268 阅读 · 0 评论 -
Swap Nodes in Pairs
题目地址:https://leetcode.com/problems/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.Yo原创 2016-12-11 15:44:48 · 223 阅读 · 0 评论 -
Assign Cookies
题目地址:https://leetcode.com/problems/assign-cookies/Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child ii has a g原创 2016-12-01 20:53:14 · 346 阅读 · 0 评论 -
Pascal's Triangle
题目地址:https://leetcode.com/problems/pascals-triangle/Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1]原创 2016-12-12 15:15:30 · 309 阅读 · 0 评论 -
Pascal's Triangle II
题目地址:https://leetcode.com/problems/pascals-triangle-ii/Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorith原创 2016-12-12 15:48:21 · 312 阅读 · 0 评论 -
Linked List Cycle
题目地址:https://leetcode.com/problems/linked-list-cycle/Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space? 题目要求判断一个单链表是不是有环,假设有两个指针p和q,都从前往后遍历这个原创 2016-12-12 16:38:18 · 270 阅读 · 0 评论 -
Balanced Binary Tree
题目地址:https://leetcode.com/problems/balanced-binary-tree/Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the原创 2016-12-12 16:59:20 · 198 阅读 · 0 评论 -
Binary Tree Level Order Traversal
题目地址:https://leetcode.com/problems/binary-tree-level-order-traversal/Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: G原创 2016-12-12 18:57:56 · 166 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
题目地址:https://leetcode.com/problems/binary-tree-level-order-traversal-ii/Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level fro原创 2016-12-12 19:04:21 · 175 阅读 · 0 评论 -
Repeated Substring Pattern
题目地址:https://leetcode.com/problems/repeated-substring-pattern/Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring toget原创 2016-12-12 21:43:43 · 899 阅读 · 0 评论 -
Remove Duplicates from Sorted List
题目地址:https://leetcode.com/problems/remove-duplicates-from-sorted-list/Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.原创 2016-12-13 10:43:23 · 314 阅读 · 0 评论 -
Climbing Stairs
题目地址:https://leetcode.com/problems/climbing-stairs/You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you cli原创 2016-12-13 11:28:51 · 256 阅读 · 0 评论 -
Find All Anagrams in a String
题目地址:https://leetcode.com/problems/find-all-anagrams-in-a-string/Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters原创 2016-12-13 23:09:17 · 355 阅读 · 0 评论 -
Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, r原创 2016-12-08 19:31:58 · 253 阅读 · 0 评论 -
Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1就是翻转二叉树,递归处理。public class InvertBinaryTree { public TreeNode invertTree(TreeN原创 2016-12-08 19:36:03 · 174 阅读 · 0 评论 -
Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.求树的所有左叶子原创 2016-12-08 21:01:36 · 228 阅读 · 0 评论 -
Move Zeroes
题目地址:https://leetcode.com/problems/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.For example, given nu原创 2016-12-08 21:54:40 · 164 阅读 · 0 评论 -
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 t原创 2016-12-08 23:17:25 · 201 阅读 · 0 评论 -
Excel Sheet Column Number
题目地址:https://leetcode.com/problems/excel-sheet-column-number/Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For exa原创 2016-12-09 09:46:53 · 180 阅读 · 0 评论 -
Valid Anagram
题目地址:https://leetcode.com/problems/valid-anagram/Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t原创 2016-12-09 11:52:27 · 84114 阅读 · 0 评论 -
Majority Element
题目地址:https://leetcode.com/problems/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原创 2016-12-09 13:07:20 · 190 阅读 · 0 评论 -
Longest Palindrome
题目地址:https://leetcode.com/problems/longest-palindrome/Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.Th原创 2016-12-09 14:38:21 · 172 阅读 · 0 评论 -
Number of Segments in a String
题目地址:https://leetcode.com/problems/number-of-segments-in-a-string/Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note th原创 2016-12-09 22:00:55 · 966 阅读 · 0 评论 -
Reverse Linked List
题目地址:https://leetcode.com/problems/reverse-linked-list/Reverse a singly linked list.就是翻转链表。逻辑很简单,但是从没用Java写过,写一个练练手吧。public class ReverseLinkedList { public ListNode reverseList(ListNode head) {原创 2016-12-09 22:36:41 · 169 阅读 · 0 评论 -
Implement strStr()
题目地址:https://leetcode.com/problems/implement-strstr/Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 这个题目中的strStr(String hays原创 2016-12-16 13:30:45 · 227 阅读 · 0 评论 -
Nth Digit
题目地址:https://leetcode.com/problems/nth-digit/Find the nthn^{th} digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …Note: n is positive and will fit within the range of a 32-bit原创 2016-12-16 17:33:58 · 278 阅读 · 0 评论