
leetcode
GODBAR
暮年诗赋动江关
展开
-
190.颠倒二进制位 && 191. 位1的个数
public int reverseBits(int n) { int r = 0; for(int i = 0;i < 32 && n != 0;i++){ r= r<<1; r = r|(n&1); n = n>>1; } return r; }public int hammingWeight(int n) { int r = 0...原创 2021-10-10 22:36:13 · 186 阅读 · 0 评论 -
leetcode25: Reverse Nodes in k-Group
Reverse Nodes in k-Group Given a linked list, reverse the nodes of a linked listk at a time and return its modified list.k is a positive integer and is less than or equal to the length of the li原创 2017-01-07 20:33:01 · 381 阅读 · 0 评论 -
leetcode26:Remove Duplicates from Sorted Array
Remove Duplicates from Sorted ArrayGiven a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another原创 2017-01-08 09:36:48 · 328 阅读 · 0 评论 -
leetcode27:Remove Element
Remove ElementGiven 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 cons原创 2017-01-08 10:34:16 · 334 阅读 · 0 评论 -
leetcode28: Implement strStr()
Implement strStrImplement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.对haystack进行遍历,比较当前下标下,长度为needle.length()长的字符串是否与原创 2017-01-11 17:08:29 · 477 阅读 · 0 评论 -
leetcode29:Divide Two Integers
Divide Two Integers Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.package leetcode;public class leet29 { public static原创 2017-01-18 16:12:40 · 462 阅读 · 0 评论 -
32. Longest Valid Parentheses
Longest Valid ParenthesesGiven a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parenthe原创 2017-02-20 21:15:55 · 471 阅读 · 0 评论 -
leetcode30:Substring with Concatenation of All Words
Substring with Concatenation of All Words转载:www.cnblogs.com/zihaowang/p/4507979.htmlYou are given a string, s, and a list of words,words, that are all of the same length. Find all starti转载 2017-02-13 14:04:28 · 444 阅读 · 0 评论 -
leetcode31. Next Permutation
Next Permutation参考:https://yq.aliyun.com/articles/863Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement i原创 2017-02-15 16:45:39 · 387 阅读 · 0 评论 -
leetcode23:Merge k Sorted Lists
Merge k Sorted Lists 参考:http://www.cnblogs.com/TenosDoIt/p/3673188.htmlMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解一:因为前面有一道题是两条原创 2016-12-30 08:41:38 · 668 阅读 · 0 评论 -
leetcode22:Generate Parentheses
Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()(原创 2016-12-27 20:51:58 · 385 阅读 · 0 评论 -
leetcode14:Longest Common Prefix
leetcode14:Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings.循环的判断数组中每一个字符串在相同的下标是否有相同的值(当然还要加入相应的判断匹配终止的条件),这样遍可以找出最长的公共前缀package lee原创 2016-12-01 11:18:04 · 374 阅读 · 0 评论 -
leetcode18:4Sum
18. 4SumGiven an array S of n integers, are there elementsa, 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:原创 2016-12-10 21:00:03 · 326 阅读 · 0 评论 -
leetcode16:3Sum Closest
3Sum Closest Given an array S of n integers, find three integers inS such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input wo原创 2016-12-02 20:15:04 · 426 阅读 · 0 评论 -
leetcode17:Letter Combinations of a Phone Number
Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone butto原创 2016-12-07 08:06:08 · 455 阅读 · 0 评论 -
leetcode19:Remove Nth Node From End of List
Remove Nth Node From End of ListGiven 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原创 2016-12-15 09:04:19 · 348 阅读 · 0 评论 -
leetcode20:Valid Parentheses
Valid ParenthesesGiven a string containing just the characters '(', ')', '{', '}', '[' and']', determine if the input string is valid.The brackets must close in the correct order, "()" and "原创 2016-12-22 21:58:04 · 472 阅读 · 0 评论 -
leetcode21:Merge Two Sorted Lists
Merge Two Sorted ListsMerge 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.两个单链表的合并package leetcode;原创 2016-12-23 21:05:18 · 409 阅读 · 0 评论 -
leetcode24:Swap Nodes in Pairs
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 on原创 2017-01-04 09:33:55 · 360 阅读 · 0 评论 -
leetcode15:3Sum
3Sum我觉得做算法题,一般在不能一下子给出最终的解得时候,应该循序渐进的结局问题,先给出一个近似正确的答案,并进行不断地修正,一步一步的逼近最终得答案,就向这道题一样,可以先实现有重复解得程序,再在这个程序的基础上实现无重复的解。package leetcode;import java.util.ArrayList;import java.util.Iterator;impo原创 2016-12-01 11:14:47 · 734 阅读 · 0 评论