LuckyPants
  • Home
  • Poems
  • Python
    • Python Interview Prep Notes for Students >
      • Merge Intervals Leetcode
      • Merge k Sorted Lists
    • Python Setup >
      • Pep 8 style guide
    • Lecture 1 - Basics
    • Lecture 2 - Loops, Lists >
      • Homework 2 Program 1 Step By Step
      • Homweork 2 Shuffle String Program
    • Lecture 3 - structures, packing, string functions >
      • Homework
      • Additional Exercises - you do not need to submit these
    • Lecture 4 - Dictionaries, Functions, Modules
    • Lecture 5 - functions, variable scope, modules >
      • Previous Exams
    • Lecture 6 - CLI, Files, Regex, pickle, shelve
    • Lecture 7 - capturing web content >
      • Processing XML data
    • Midterm Prep >
      • Programming assignment prep
    • Lecture 8 - Exceptions, Classes, Inheritance >
      • Exceptions Recording
      • Multiple Except Clauses Recording
      • Eating an Exception Recording
      • finally and else clause recordings
      • Exception Stack Trace Recording
      • exit() and CTRL+C
      • Class Variables Recording
      • Static Methods and Class Methods Recording
      • Inheritance Recordings
    • Section 9 - db, flask, pip >
      • Accessing Databases
      • HTTP Server
      • Web Applications
      • Finding and installing additional Libraries with pip
      • Web Services with Flask
      • Calling Web Services from Python
      • Placing your application on the web
    • Section 10 - flask, grpc, venv, docker >
      • Flask based Web Applications
      • gRPC
      • Packaging, Dependencies and Virtual Environments
      • Dockerized Python Application
    • Section 11 - Django, GUI >
      • Cross Site Scripting XSS and markupsafe
      • Django >
        • Cross Site Request Forgery CSRF
      • tkinter - frame and button
      • Toplevel
      • Frame
      • Mouse and Keyboard Events
      • Canvas
      • Menu
      • Radiobuttons and Checkboxes
      • Entry
      • ImageMagic
    • Lecture 12 - WebSockets, System Monitoring, PyGame >
      • Web Sockets
      • PyGame Platformer
    • Lecture 13 - Data Structure and Algorithms >
      • Arrays and Strings
      • Dictionaries
      • Linked Lists
      • Trees
      • Stack and Queue
      • Sets
      • Merge Sort
      • Coverage Reports
    • Lecture 14 - Subprocesses, Threads, Multiprocessing >
      • Graphs
      • Singleton Design Pattern
      • Subprocesses and Multithreading
      • Jupiter Notebooks
      • Pandas Operations
    • Extra >
      • Raspberry Pi
      • Raspberry PI home security
      • OpenCV and template matching
      • Compare SQLite DB's in Python
      • Natural Language Processing and nltk
      • Hackathon Projects
  • SaaS
    • Java Interview Prep Notes for Students
    • Setup >
      • SaaS and Cloud Computing
      • Eclipse set up
      • Building web application in Eclipse using Tomcat
    • Section2 >
      • Maven Intro
      • Set up a simple web app and deploy on Heroku
      • Add Jersey Dependencies
      • Dissecting our first REST service
    • Section3 >
      • Jackson intro
      • @POST, @PUT, @DELETE
      • Your Project
    • Section4 >
      • Rules of Injection
      • Root Resource, Subresource, Subresource Locator
      • @CONTEXT
    • Section 5 >
      • Heroku, Java, Jersey and Postgres
      • Music Store with Postgres
      • Working with Files
      • Storing files in Postgres
      • Homework
    • Section 6 >
      • Books Store with Mongo
      • Google APIs
      • Twitter APIs
      • Properties for a web application
      • Homework
    • Section 7 >
      • Jersey Client Famework
      • Java Jersey SalesForce and OAuth
      • Servlets and JSP
      • Data access examples
    • Section 8 >
      • MVC - Model View Controller
      • JSTL Core tags
      • Scopes
      • Building Services to work with forms
    • Section 9 >
      • Calling REST services with JQuery
      • Angular.js
    • Section 10 >
      • consuming SOAP services
      • Web Sockets
      • Websockets, continued
    • Section 11 - Software Development Methodologies, Testing, Performance and Security >
      • Software Development Methodologies
      • Testing, Performance and Security
    • Your Project
    • Previous Projects
    • Course Project Submission
    • SaaS Projects
    • Install Tomcat on Mac

remove duplicates from sorted array

10/4/2020

1 Comment

 
​​​https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/
class Solution {
    public int removeDuplicates(int[] nums) {
            if(nums.length < 1) return 0;
                int len = 0;
                int cur = nums[0];
                int cur_ind = 0;
                for(int i =1; i < nums.length; ++i){
                    if(nums[i] != cur){
                        len+=1;
                        cur = nums[i];
                        cur_ind +=1;
                        System.out.println(nums[cur_ind]=cur);
                    }
                }
                Arrays.copyOfRange(nums, 0, len);
                return len + 1;
            }
}
1 Comment
Vanviet Blog link
7/10/2023 06:37:16 am

Thank youu for sharing this

Reply



Leave a Reply.

    This is a collection of interview prep programs, online resources that were used in my Java classes. The Java classes were taught years ago, hence the material is likely outdated, I will make an effort to go through it and update as time permits

    Categories

    All
    Algorithms
    Basics
    Leetcode

  • Home
  • Poems
  • Python
    • Python Interview Prep Notes for Students >
      • Merge Intervals Leetcode
      • Merge k Sorted Lists
    • Python Setup >
      • Pep 8 style guide
    • Lecture 1 - Basics
    • Lecture 2 - Loops, Lists >
      • Homework 2 Program 1 Step By Step
      • Homweork 2 Shuffle String Program
    • Lecture 3 - structures, packing, string functions >
      • Homework
      • Additional Exercises - you do not need to submit these
    • Lecture 4 - Dictionaries, Functions, Modules
    • Lecture 5 - functions, variable scope, modules >
      • Previous Exams
    • Lecture 6 - CLI, Files, Regex, pickle, shelve
    • Lecture 7 - capturing web content >
      • Processing XML data
    • Midterm Prep >
      • Programming assignment prep
    • Lecture 8 - Exceptions, Classes, Inheritance >
      • Exceptions Recording
      • Multiple Except Clauses Recording
      • Eating an Exception Recording
      • finally and else clause recordings
      • Exception Stack Trace Recording
      • exit() and CTRL+C
      • Class Variables Recording
      • Static Methods and Class Methods Recording
      • Inheritance Recordings
    • Section 9 - db, flask, pip >
      • Accessing Databases
      • HTTP Server
      • Web Applications
      • Finding and installing additional Libraries with pip
      • Web Services with Flask
      • Calling Web Services from Python
      • Placing your application on the web
    • Section 10 - flask, grpc, venv, docker >
      • Flask based Web Applications
      • gRPC
      • Packaging, Dependencies and Virtual Environments
      • Dockerized Python Application
    • Section 11 - Django, GUI >
      • Cross Site Scripting XSS and markupsafe
      • Django >
        • Cross Site Request Forgery CSRF
      • tkinter - frame and button
      • Toplevel
      • Frame
      • Mouse and Keyboard Events
      • Canvas
      • Menu
      • Radiobuttons and Checkboxes
      • Entry
      • ImageMagic
    • Lecture 12 - WebSockets, System Monitoring, PyGame >
      • Web Sockets
      • PyGame Platformer
    • Lecture 13 - Data Structure and Algorithms >
      • Arrays and Strings
      • Dictionaries
      • Linked Lists
      • Trees
      • Stack and Queue
      • Sets
      • Merge Sort
      • Coverage Reports
    • Lecture 14 - Subprocesses, Threads, Multiprocessing >
      • Graphs
      • Singleton Design Pattern
      • Subprocesses and Multithreading
      • Jupiter Notebooks
      • Pandas Operations
    • Extra >
      • Raspberry Pi
      • Raspberry PI home security
      • OpenCV and template matching
      • Compare SQLite DB's in Python
      • Natural Language Processing and nltk
      • Hackathon Projects
  • SaaS
    • Java Interview Prep Notes for Students
    • Setup >
      • SaaS and Cloud Computing
      • Eclipse set up
      • Building web application in Eclipse using Tomcat
    • Section2 >
      • Maven Intro
      • Set up a simple web app and deploy on Heroku
      • Add Jersey Dependencies
      • Dissecting our first REST service
    • Section3 >
      • Jackson intro
      • @POST, @PUT, @DELETE
      • Your Project
    • Section4 >
      • Rules of Injection
      • Root Resource, Subresource, Subresource Locator
      • @CONTEXT
    • Section 5 >
      • Heroku, Java, Jersey and Postgres
      • Music Store with Postgres
      • Working with Files
      • Storing files in Postgres
      • Homework
    • Section 6 >
      • Books Store with Mongo
      • Google APIs
      • Twitter APIs
      • Properties for a web application
      • Homework
    • Section 7 >
      • Jersey Client Famework
      • Java Jersey SalesForce and OAuth
      • Servlets and JSP
      • Data access examples
    • Section 8 >
      • MVC - Model View Controller
      • JSTL Core tags
      • Scopes
      • Building Services to work with forms
    • Section 9 >
      • Calling REST services with JQuery
      • Angular.js
    • Section 10 >
      • consuming SOAP services
      • Web Sockets
      • Websockets, continued
    • Section 11 - Software Development Methodologies, Testing, Performance and Security >
      • Software Development Methodologies
      • Testing, Performance and Security
    • Your Project
    • Previous Projects
    • Course Project Submission
    • SaaS Projects
    • Install Tomcat on Mac