LeetCode 刷题以及自己的思路

刷题记录,code代表题目顺序

code1

class Solution {
   
		    public int[] twoSum(int[] nums, int target) {
   
		        int res[]=new int[2];
		     int len=nums.length;
		     for(int i=0;i<len;i++){
   
		         for(int j=i+1;j<len;j++){
   
		             if(nums[i]+nums[j]==target){
   
		                 res[0]=i;
		                 res[1]=j;
		             }
		         }
		     }
		     
		     return res;
		          
		    }
		}

code2

public class Code2 {
   
	 static class ListNode {
   
		      int val;
		      ListNode next;
		      ListNode(int x) {
    val = x; }
		  }

	public static void main(String[] args) {
   
		// TODO Auto-generated method stub

		ListNode t=new ListNode(8);
		ListNode t1=new ListNode(5);
	//测试代码
	t=	addTwoNumbers(t1, t);
	while (t!=null) {
   
	System.out.println(t.val);
	t=t.next;
	}
		
	}

	private boolean flag=false;
	private static int topInt=0;
 	    public  static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
   
    	//找到头节点出队,相加
    
    	ListNode l3=null;
    	
    	ListNode temp=null;
    	ListNode temp2=null;
    	ListNode head=null;
    	boolean flag=false;
    	while (l1!=null||l2!=null||flag!=false) {
   
    		int val1=0;
    		int val2=0;
    		if(l1!=null) {
   
    		 val1=l1.val;
    		}else {
   
    			val1=0;
    		}
    		if(l2!=null) {
   
        		 val2=l2.val;
        		}else {
   
        			val2=0;
        		}
    		
    		if(l1==null) {
   
    			l1=null;			
			}else {
   
				l1=l1.next;
			}
    		if(l2==null) {
   
    			l2=null;		
			}else {
   
				l2=l2.next;	
			}
    		if(flag) {
   
    			val1=val1+1+val2;
    			flag=false;
    			
    		}else {
   
    			val1=val1+val2;
			}
    		if(val1>=10) {
   
    			flag=true;
    		}
    		val1=val1%10;
    		if(l3==null) {
   
                l3=new ListNode(val1);
    			//l3.val=val1;
    			l3.next=null;
    			head=l3;
    		}else {
   
    			ListNode tl3=new ListNode(val1);
    			//tl3.val=val1;
    			tl3.next=null;
    		
    			head.next=tl3;
    			head=tl3;
    		}
		}
    	
    	
		return l3;
 
    }
    
    

}

code3

class Solution {
   
	public static void main(String[] args) {
   
		//模拟动态规划做此题
		lengthOfLongestSubstring("abcd");
		
		
	}
	private static char[] charas;
    public static  int lengthOfLongestSubstring(String s) {
   
    	charas=new char[s.length()];
    	charas=s.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值