Leetcode
文章平均质量分 64
pessis1
这个作者很懒,什么都没留下…
展开
-
Leetcode 389 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 at a random position.Find the letter tha原创 2016-09-22 20:00:55 · 197 阅读 · 0 评论 -
Leetcode 415 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 Both num1 and num2 contains only digits 0-9.Both num1 and n原创 2016-10-09 18:46:31 · 253 阅读 · 0 评论 -
Leetcode 383 Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constru原创 2016-10-10 15:09:18 · 315 阅读 · 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-10-10 15:22:33 · 380 阅读 · 0 评论 -
Leetcode 349 Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note: Each element in the result must be unique. The re原创 2016-10-10 17:43:09 · 210 阅读 · 0 评论 -
Leetcode 100 SameTree
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./**原创 2016-10-10 18:09:28 · 243 阅读 · 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 only one digit,原创 2016-09-21 19:55:40 · 198 阅读 · 0 评论 -
Leetcode 350 Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as ma原创 2016-10-25 18:10:00 · 284 阅读 · 0 评论 -
Leetcode 401 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 zero or one, with the least significant bit o原创 2016-10-26 14:45:17 · 293 阅读 · 0 评论 -
Leetcode 13 Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.罗马数字是阿拉伯数字传入之前使用的一种数码。罗马数字采用七个罗马字母作数字、即Ⅰ(1)、X(10)、C(100)、M(1000)、V(5)、L(50)、D(500)原创 2016-10-26 16:14:12 · 152 阅读 · 0 评论 -
Leetcode 266 Invert the binary tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * public class TreeNode {原创 2016-09-30 20:15:07 · 217 阅读 · 0 评论 -
Leetcode 206 Reverse Linked List
Reverse a singly linked list.题意简单粗暴 reverse链表 有两种做法第一种 使用循环语句 将两两相邻的节点进行reversepublic ListNode reverseList(ListNode head) { if(head==null||head.next==null) return head; List原创 2016-10-26 20:52:13 · 145 阅读 · 0 评论 -
Leetcode 171 Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... AAA原创 2016-10-18 15:44:35 · 176 阅读 · 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-10-18 19:59:34 · 356 阅读 · 0 评论 -
Leetcode 387 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.public class原创 2016-10-18 16:08:09 · 344 阅读 · 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-10-19 16:25:23 · 265 阅读 · 0 评论 -
Leetcode 217 Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2016-10-19 20:15:15 · 146 阅读 · 0 评论 -
Leetcode 405 Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complementmethod is used.Note:All letters in hexadecimal (a-f) must be in lowercase.The hexadec原创 2016-10-29 14:54:23 · 351 阅读 · 0 评论 -
Leetcode 326 Power of Three
326. Power of Three sGiven 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?pu原创 2016-10-29 15:37:47 · 267 阅读 · 0 评论 -
Leetcode 283 Move zeros
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-10-08 18:10:00 · 595 阅读 · 0 评论 -
Leetcode 404 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-10-08 18:39:20 · 209 阅读 · 0 评论 -
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-11-28 17:35:07 · 171 阅读 · 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-11-01 13:56:27 · 267 阅读 · 0 评论 -
Leetcode 463 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/vertically (not diagonally). The grid is completely原创 2016-11-29 11:12:21 · 176 阅读 · 0 评论 -
Leetcode 455 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 i has a greed factor gi, which is the minimum size of a c原创 2016-11-29 13:32:42 · 192 阅读 · 0 评论 -
Leetcode 453 Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Ou原创 2016-11-29 14:38:04 · 376 阅读 · 0 评论 -
Leetcode 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?本来用的递归 结果迭代太多 超时了然后才明白这就原创 2016-11-29 18:16:29 · 462 阅读 · 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-11-29 18:33:24 · 138 阅读 · 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-11-29 18:59:48 · 406 阅读 · 0 评论 -
Leetcode 21 Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.没啥要说的 只是自己要仔细一点啊/** * Definition for singly-linked lis原创 2016-11-29 20:35:18 · 374 阅读 · 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-11-29 21:09:34 · 310 阅读 · 0 评论 -
Letcode 198 House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent hou原创 2016-11-30 10:58:02 · 258 阅读 · 0 评论 -
Leetcode 342 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 false.要考虑负数的情况啊。。。public class So原创 2016-11-30 12:01:29 · 360 阅读 · 0 评论 -
Leercode 345 Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Note原创 2016-11-30 13:04:17 · 326 阅读 · 0 评论 -
Leetcode 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-11-30 13:41:54 · 383 阅读 · 0 评论 -
Leetcode 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-11-30 15:31:12 · 175 阅读 · 0 评论 -
Leetcode 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-12-14 17:59:35 · 188 阅读 · 0 评论 -
Leetcode 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.二叉树的最小路径问题 值得注意的一个地方是 当前根节点的原创 2016-12-14 18:37:25 · 228 阅读 · 0 评论 -
Leetcode 19.Remove Nth Node From End of List
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-12-14 20:09:47 · 145 阅读 · 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-14 20:36:03 · 237 阅读 · 0 评论