#合并两个有序链表
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
if(l1 == null) {
return l2;
}
if(l2 == null) {
return l1;
}
if(l1.val < l2.val) {
l1.next = mergeTwoLists(l1.next, l2);
return l1;
} else {
l2.next = mergeTwoLists(l1, l2.next);
return l2;
}
}
}
#删除有序数组中的重复项
class Solution {
public int removeDuplicates(int[] nums) {
int i=0,j=0;
int len=nums.length;
for(j=0;j<len;j++)
{
if(nums[j]!=nums[i])
{
nums[++i]=nums[j];
}
}
return i+1;
}
}
#速算机器人
class Solution {
public int calculate(String s) {
int len=s.length();
int x=1,y=0;
for(int i=0;i<len;i++)
{
if(s.charAt(i)=='A') x=2*x+y;
else if(s.charAt(i)=='B') y=2*y+x;
}
return (x+y);
}
}
#拿硬币
class Solution {
public int minCount(int[] coins) {
int sum=0;
for(int i=0;i<coins.length;i++)
{
if(coins[i]%2==0) sum=sum+(coins[i]/2);
else if(coins[i]%2!=0) sum=sum+(coins[i]/2+1);
}
return sum;
}
}