LeetCode
文章平均质量分 50
LSF_Kevin
LSF
展开
-
【LeetCode】 003. 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 length is 3.Given "bbbbb", the answer is "原创 2016-12-18 03:31:28 · 128 阅读 · 0 评论 -
【LeetCode】 006. 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原创 2016-07-28 21:00:31 · 179 阅读 · 0 评论 -
【LeetCode】 007. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321public class Solution { public int reverse(int x) { long sum = 0; while (x != 0)原创 2016-07-28 21:02:02 · 304 阅读 · 0 评论 -
【LeetCode】 001. 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.Example:Given nums =原创 2016-07-28 19:56:45 · 189 阅读 · 0 评论 -
【LeetCode】 009. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no原创 2016-07-28 21:04:51 · 211 阅读 · 0 评论 -
【LeetCode】 008. String to Integer (atoi)
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原创 2016-07-28 21:03:55 · 203 阅读 · 0 评论 -
【LeetCode】 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2016-12-21 10:36:18 · 118 阅读 · 0 评论 -
【LeetCode】 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co原创 2016-12-21 11:34:18 · 120 阅读 · 0 评论 -
【LeetCode】 168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB public原创 2016-12-21 12:20:32 · 118 阅读 · 0 评论 -
【LeetCode】 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原创 2016-12-21 12:42:28 · 101 阅读 · 0 评论 -
【LeetCode】 171. 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 example: A -> 1 B -> 2 C -> 3 ...原创 2016-12-22 05:49:28 · 162 阅读 · 0 评论 -
【LeetCode】 172. Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.public class Solution { public int trailingZeroes(int n) {原创 2016-12-22 07:09:07 · 153 阅读 · 0 评论 -
【LeetCode】 189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].public class Solution { public void rotat原创 2016-12-22 07:25:58 · 181 阅读 · 0 评论 -
【LeetCode】 190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2016-12-22 07:50:39 · 155 阅读 · 0 评论 -
【LeetCode】 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000原创 2016-12-22 13:24:59 · 139 阅读 · 0 评论 -
【LeetCode】 202. Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares原创 2016-12-22 22:31:38 · 156 阅读 · 0 评论 -
【LeetCode】 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** * Definition for si原创 2016-12-22 22:49:32 · 194 阅读 · 0 评论 -
【LeetCode】 204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.public class Solution { public int countPrimes(int n) { boolean[] temp = new boolean[n]; in原创 2016-12-22 23:05:22 · 182 阅读 · 0 评论 -
【LeetCode】 205. Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot原创 2016-12-23 00:01:06 · 185 阅读 · 0 评论 -
【LeetCode】 206. Reverse Linked List
Reverse a singly linked list./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class So原创 2016-12-23 00:35:45 · 139 阅读 · 0 评论 -
【LeetCode】 219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.原创 2016-12-23 00:49:55 · 148 阅读 · 0 评论 -
【LeetCode】 223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota原创 2016-12-23 06:17:04 · 163 阅读 · 0 评论 -
【LeetCode】 225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet原创 2016-12-23 06:32:50 · 141 阅读 · 0 评论 -
【LeetCode】 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howe原创 2016-12-23 06:44:39 · 133 阅读 · 0 评论 -
【LeetCode】 231. Power of Two
Given an integer, write a function to determine if it is a power of two.public class Solution { public boolean isPowerOfTwo(int n) { if (n <= 0) { return false; }原创 2016-12-23 06:58:29 · 132 阅读 · 0 评论 -
【LeetCode】 232. Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(原创 2016-12-23 08:34:47 · 139 阅读 · 0 评论 -
【LeetCode】 002. Add Two Number
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-12-18 06:35:01 · 151 阅读 · 0 评论 -
【LeetCode】 012. Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public String intToRoman(int num) { String M[] = {原创 2016-12-18 06:49:02 · 150 阅读 · 0 评论 -
【LeetCode】 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?/** * Definition for singly-linked list. * public class ListNode { *原创 2016-12-23 21:59:08 · 128 阅读 · 0 评论 -
【LeetCode】 235. Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2016-12-23 22:52:26 · 129 阅读 · 0 评论 -
【LeetCode】 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-12-23 22:56:33 · 105 阅读 · 0 评论 -
【LeetCode】 242. 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 = "car", return false.Note:You may ass原创 2016-12-23 23:08:48 · 130 阅读 · 0 评论 -
【LeetCode】 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/**原创 2016-12-24 02:01:15 · 155 阅读 · 0 评论 -
【LeetCode】 258. 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 on原创 2016-12-24 07:15:07 · 135 阅读 · 0 评论 -
【LeetCode】 263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc原创 2016-12-24 07:21:15 · 138 阅读 · 0 评论 -
【LeetCode】 278. First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the原创 2016-12-24 07:52:21 · 132 阅读 · 0 评论 -
【LeetCode】 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.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2016-12-24 08:03:39 · 127 阅读 · 0 评论 -
【LeetCode】 290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2016-12-24 08:23:08 · 137 阅读 · 0 评论 -
【LeetCode】 292. 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-12-24 08:47:10 · 138 阅读 · 0 评论 -
【LeetCode】 299. Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2016-12-24 13:00:33 · 139 阅读 · 0 评论