LeetCode
文章平均质量分 61
强哥快飞
这个作者很懒,什么都没留下…
展开
-
LeetCode 之RemoveElement
题目: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2015-01-07 15:47:54 · 361 阅读 · 0 评论 -
LeetCode 之 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原创 2015-01-03 04:37:28 · 298 阅读 · 0 评论 -
LeetCode 之 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2014-12-26 16:10:01 · 289 阅读 · 0 评论 -
leetcode remove duplicate of sorted list
/** * Given a sorted linked list, delete all duplicates such that each element appear only once. * */很简单,没有啥可说的public void removeDuplicates(ListNode node){ListNode cur = node;while(cur!=原创 2015-01-30 01:30:17 · 307 阅读 · 0 评论 -
求该整数的二进制表达中有多少个1
题目:输入一个整数,求该整数的二进制表达中有多少个1。例如输入10,由于其二进制表示为1010,有两个1,因此输出2。分析:这是一道很基本的考查位运算的面试题。包括微软在内的很多公司都曾采用过这道题。一个很基本的想法是,我们先判断整数的最右边一位是不是1。接着把整数右移一位,原来处于右边第二位的数字现在被移到第一位了,再判断是不是1。这样每次移动一位,直到这个整数变成0为止。现在的原创 2015-01-29 11:56:07 · 630 阅读 · 0 评论 -
leetcode MergeTwoSortedList
/** * * 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. * */key Notethe solution is sam原创 2015-01-30 02:05:32 · 321 阅读 · 0 评论 -
PlusOne
/** * 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.原创 2015-01-27 04:58:26 · 461 阅读 · 0 评论 -
leetcode 之 二进制数相加
/** * Given two binary strings, return their sum (also a binary string). * * For example, a = "11" b = "1" Return "100". * * 题目翻译: * * 给定两个二进制字符串,返回它们的和(也是一个二进制字符串)。 例如, a = "11" b =原创 2015-01-27 04:55:19 · 337 阅读 · 0 评论 -
leetCode 之SearchInsertPosition
题目:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.其实就是查找的扩展两种, 递归和迭代 // 递归 pub原创 2015-01-07 16:01:27 · 353 阅读 · 0 评论 -
连续最大和自数组
题目:/** * Find the contiguous subarray within an array (containing at least one number) * which has the largest sum. For example, given the array [-2, 1, -3, 4, -1, * 2,1, -5, 4 ], the contiguo原创 2015-01-27 04:57:54 · 403 阅读 · 0 评论 -
leetcode 之 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, ret原创 2015-01-27 04:52:15 · 293 阅读 · 0 评论 -
leetCode 之 两个二进制数相加
题目: * Given two binary strings, return their sum (also a binary string). * * For example, a = "11" b = "1" Return "100". * * 题目翻译: * * 给定两个二进制字符串,返回它们的和(也是一个二进制字符串)。 例如, a = "11" b =原创 2015-01-07 15:50:33 · 1161 阅读 · 0 评论 -
LeetCode 之 preorder traversal of binary tree
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive sol原创 2015-01-03 04:43:06 · 349 阅读 · 0 评论