![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
Alan_Xiang
在读学生
展开
-
419. Battleships in a Board(计算甲板上的军舰数)
Given an 2D board, count how many different battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:You receiv原创 2016-11-04 13:23:28 · 1634 阅读 · 0 评论 -
338. Counting Bits(计算整数二进制表示中1的位数)
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5原创 2016-11-07 13:08:40 · 587 阅读 · 0 评论 -
1. 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-10-27 17:07:14 · 324 阅读 · 0 评论 -
6. 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-10-27 17:08:55 · 252 阅读 · 0 评论 -
7. Reverse Integer (转置整数)
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you原创 2016-10-27 17:10:47 · 308 阅读 · 0 评论 -
8. 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-10-27 17:12:05 · 589 阅读 · 0 评论 -
9. 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-10-27 17:14:04 · 475 阅读 · 0 评论 -
13. Roman to Integer (罗马数字转int)
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public int romanToInt(String s) { if(s.length() <原创 2016-10-27 17:15:21 · 337 阅读 · 0 评论 -
14. Longest Common Prefix (计算一组字符串最长公共前缀)
Write a function to find the longest common prefix string amongst an array of strings.public class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0)原创 2016-10-27 17:18:01 · 449 阅读 · 0 评论 -
19. Remove Nth Node From End of 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 removing the second node from the end, the原创 2016-10-27 17:25:12 · 259 阅读 · 0 评论 -
20. Valid Parentheses (括号匹配)
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原创 2016-10-27 17:27:08 · 421 阅读 · 0 评论 -
24. 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原创 2016-10-27 21:46:21 · 404 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array(移除有序数组中的重复元素)
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2016-10-27 21:48:34 · 459 阅读 · 0 评论 -
27. Remove Element(移除数组中与指定值相等的元素)
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.原创 2016-10-27 21:50:47 · 450 阅读 · 0 评论 -
28. Implement strStr() (返回子串在字符串中第一次出现的位置)
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.public class Solution { public int strStr(String haystack, Strin原创 2016-10-27 21:52:32 · 433 阅读 · 0 评论 -
36. 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 with the character '.'.A partially fille原创 2016-10-27 21:55:01 · 515 阅读 · 0 评论 -
38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2016-10-27 21:56:41 · 235 阅读 · 0 评论 -
58. 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原创 2016-10-27 21:57:39 · 664 阅读 · 0 评论 -
66. Plus One (计算数字加1后的结果)
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.public class Solutio原创 2016-10-27 22:00:31 · 390 阅读 · 0 评论 -
67. Add Binary (二进制求和)
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".public class Solution { public String addBinary(String a, String b) {原创 2016-10-27 22:01:22 · 486 阅读 · 0 评论 -
70. 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 climb to the top?public class Solution {原创 2016-10-27 22:02:38 · 246 阅读 · 0 评论 -
83. 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.Given 1->1->2->3->3, return 1->2->3./** * Definition for s原创 2016-10-27 22:03:12 · 251 阅读 · 0 评论 -
88. Merge Sorted Array (合并有序数组)
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add原创 2016-10-27 22:04:29 · 268 阅读 · 0 评论 -
100. Same Tree (判断二叉树是否相等)
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Def原创 2016-10-27 22:05:33 · 448 阅读 · 0 评论 -
101. Symmetric Tree (判断二叉树是否对称)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2016-10-27 22:07:12 · 994 阅读 · 0 评论 -
102. 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:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 2原创 2016-10-27 22:08:16 · 378 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree (二叉树最大深度)
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for a binary tre原创 2016-10-27 22:09:35 · 277 阅读 · 0 评论 -
107. 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 from leaf to root).For example:Given binary tree [3,9,20,null,null,1原创 2016-10-27 22:11:05 · 525 阅读 · 0 评论 -
110. 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 depth of the two subtrees of every node never diffe原创 2016-10-27 22:12:05 · 549 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree (计算二叉树最小深度)
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for a binary tre原创 2016-10-27 22:13:22 · 347 阅读 · 0 评论 -
112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2016-10-27 22:48:38 · 248 阅读 · 0 评论 -
119. Pascal's Triangle II (杨辉三角 第k行)
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 algorithm to use only O(k) extra space?原创 2016-10-27 22:54:29 · 376 阅读 · 0 评论 -
118. Pascal's 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], [1,4,6,4,1]]public class Solu原创 2016-10-27 22:52:14 · 310 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock ()
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2016-10-27 22:57:27 · 266 阅读 · 0 评论 -
125. Valid Palindrome (回文字符串判断)
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2016-10-27 22:59:37 · 425 阅读 · 0 评论 -
136. 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 complexity. Could you implement it without using e原创 2016-10-27 23:01:45 · 745 阅读 · 0 评论 -
141. 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?/** * Definition for singly-linked list. * class ListNode { * int val; *原创 2016-10-27 23:04:32 · 356 阅读 · 0 评论 -
155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2016-10-27 23:07:24 · 232 阅读 · 0 评论 -
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-10-27 23:10:18 · 426 阅读 · 0 评论 -
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-10-27 23:11:47 · 673 阅读 · 0 评论