分类: 算法

记录点滴,修炼自己。
0

leetcode [#22]

题目 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: [ “((()))”, “(()())”, “(())()”, “()(())”,

0

leetcode [#217]

题目 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 elemen

0

leetcode [#21]

题目 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. 解决方案123456789101112131415161718192021222324252627282

0

leetcode [#206]

题目 Reverse a singly linked list. 解决方案123456789101112131415161718192021222324252627282930313233/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode n

0

leetcode [#204]

题目 Count the number of prime numbers less than a non-negative number, n. 解决方案12345678910111213141516171819public class Solution { public int countPrimes(int n) { if(n <= 2) r

0

leetcode [#205]

题目 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 anothe

0

leetcode [#202]

题目 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 square

0

leetcode [#203]

题目 Remove all elements from a linked list of integers that have value val. Example:Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6Return: 1 –> 2 –> 3 –> 4 –> 5 解决方案123

0

leetcode [#20]

题目 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 valid

0

leetcode [#19]

题目 Given a linked list, remove the nth node from the end of list and return its head. Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the

0

leetcode [#189]

题目 Rotate an array of n elements to the right by k steps. 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]. Note:Try to come up as many solutions as you can, ther

0

leetcode [#179]

题目 Given a list of non negative integers, arrange them such that they form the largest number. Example:Given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very lar

0

leetcode [#171]

题目 Given a column title as appear in an Excel sheet, return its corresponding column number. Note:A -> 1B -> 2C -> 3…Z -> 26AA -> 27AB -> 28 解决方案1234567public class Solution

0

leetcode [#172]

题目 Given an integer n, return the number of trailing zeroes in n!. Note:Your solution should be in logarithmic time complexity. 解决方案12345678910public class Solution { public int trailingZer

0

leetcode [#169]

题目 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 a

0

leetcode [#168]

题目 Given a positive integer, return its corresponding column title as appear in an Excel sheet. Example:1 -> A2 -> B3 -> C…26 -> Z27 -> AA28 -> AB 解决方案123456789101112131415161718

0

leetcode [#167]

题目 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbe

0

leetcode [#165]

题目 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

0

leetcode [#155]

题目 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

0

leetcode [#160]

题目 Write a program to find the node at which the intersection of two singly linked lists begins. Example:the following two linked lists:A: a1 → a2 ↘ c1