摘要:
题目大意:删除数组中的给定值,返回数组的长度。要求:1、不能申请额外的数组空间。 阅读全文
摘要:
题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack 阅读全文
摘要:
题目: 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. 题目大意 阅读全文
摘要:
public class Solution { List> res = new ArrayList>(); public List> threeSum(int[] nums) { if(nums.length 0 && nums[i] == nums[i-1]) continue; ... 阅读全文
摘要:
思路是:先取一个指针,让这个指针到达第n个节点,然后在取一个节点指向头节点,两个指针同时向后移动,直到第一个指针指向尾节点,此时第二个指针指向的节点就是要删 除的节点的前一个节点。 阅读全文
摘要:
好像写的略过于麻烦了。思路是:以数组中的第一个字符串为基准,逐个扫描剩下的字符串中是不是以这个字符串为开头,如果全是,则这个字符串就为最长公共前缀字符串,否 则,让第一个字符串的长度向前走一个,以这个字符串为基准,继续寻找。 另一种实现方法: 阅读全文
摘要:
题目大意: 有一个高度的数组,从中找出两个高度,这两个高度形成一个水桶,求出能够满足随同的最大体积。 解法: 1、两层for循环,每两个高度之间算一下体积,返回最大的体积(估计会超时)。 2、设置一个两个指针,一个指向头,一个指向尾部。算一下体积,如果头指针高度小于尾指针高度,头指针加一,反之尾指针 阅读全文
摘要:
public class Solution { public boolean isPalindrome(int x) { if(x < 0) return false; if(x < 10) return true; int i = 1; ... 阅读全文
摘要:
#include using namespace std; int main() { int n; cin >> n; int count = 0; while(n) { n = n&(n-1); count++; } cout << count << endl; return 0; } 阅读全文
摘要:
也许是我没有理解清楚题意,为什么输入+-2的时候要输出0,而不是输出2呢。 阅读全文